aboutsummaryrefslogtreecommitdiff
path: root/src/Hashmap.c
diff options
context:
space:
mode:
authorMikhail Romanko <me@blankhex.com>2025-08-04 20:30:30 +0300
committerMikhail Romanko <me@blankhex.com>2025-08-04 20:30:30 +0300
commitdeb4ec00f4e8053bab8235e1137eb7e499904db1 (patch)
tree8c7c4bbd78a366a87362423615cb1d1c786e1504 /src/Hashmap.c
parent0da77c00d652c13a99961d845a0a593dc54f1e49 (diff)
downloadbhlib-deb4ec00f4e8053bab8235e1137eb7e499904db1.tar.gz
Add macro functions for checking unsigned wraps
Diffstat (limited to 'src/Hashmap.c')
-rw-r--r--src/Hashmap.c10
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;