diff options
Diffstat (limited to 'src/Hashmap.c')
| -rw-r--r-- | src/Hashmap.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/Hashmap.c b/src/Hashmap.c index 8253ec6..8ecadf8 100644 --- a/src/Hashmap.c +++ b/src/Hashmap.c @@ -62,16 +62,16 @@ static int BH_CalcCapacity(size_t size, *threshold = *capacity * factor; while (size > *threshold) { - *capacity *= 2; - *threshold = *capacity * factor; - /* Catch capacity overflow */ - if (*capacity < 16) + if (BH_CHECK_UMUL_WRAP(*capacity, 2, size_t)) return BH_OOM; + + *capacity *= 2; + *threshold = *capacity * factor; } /* Catch malloc overflow */ - if (*capacity >= ((size_t)-1) / sizeof(BH_HashmapNode)) + if (BH_CHECK_UMUL_WRAP(*capacity, sizeof(BH_HashmapNode), size_t)) return BH_OOM; return BH_OK; |
