summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2014-06-15 11:21:17 +0000
committerXavier Roche <xroche@users.noreply.github.com>2014-06-15 11:21:17 +0000
commit4c876451be1a5e6ace67830130efc882ee3d2195 (patch)
tree7bb5e10f310c9cd40ecdd2554ddfd87d969eb607 /src
parentc5003322b79ff69779319af0944daf0248cc5c9e (diff)
Fixed log size limit check.
Diffstat (limited to 'src')
-rw-r--r--src/coucal.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/coucal.c b/src/coucal.c
index 4075b6f..efe0923 100644
--- a/src/coucal.c
+++ b/src/coucal.c
@@ -1319,19 +1319,21 @@ intptr_t coucal_get_intptr(coucal hashtable, coucal_key_const name) {
static INTHASH_INLINE size_t coucal_get_pow2(size_t initial_size) {
size_t size;
for(size = MIN_LG_SIZE
- ; size < COUCAL_HASH_SIZE && POW2(size) < initial_size
+ ; size <= COUCAL_HASH_SIZE && POW2(size) < initial_size
; size++) ;
return size;
}
coucal coucal_new(size_t initial_size) {
const size_t lg_size = coucal_get_pow2(initial_size);
- coucal hashtable =
- lg_size < COUCAL_HASH_SIZE ? (coucal) calloc(1, sizeof(struct_coucal)) : NULL;
+ const int lg_valid = lg_size <= COUCAL_HASH_SIZE
+ && lg_size < sizeof(size_t)*8;
+ coucal hashtable = lg_valid
+ ? (coucal) calloc(1, sizeof(struct_coucal)) : NULL;
coucal_item *const items =
(coucal_item *) calloc(POW2(lg_size), sizeof(coucal_item));
- if (lg_size < COUCAL_HASH_SIZE && items != NULL && hashtable != NULL) {
+ if (lg_valid && items != NULL && hashtable != NULL) {
hashtable->lg_size = lg_size;
hashtable->items = items;
hashtable->used = 0;