src/hash_map.c

changeset 1040
1ecf4dbbc60c
parent 994
3603bdf4a78b
--- a/src/hash_map.c	Fri Dec 20 21:25:33 2024 +0100
+++ b/src/hash_map.c	Sat Dec 21 21:03:28 2024 +0100
@@ -30,6 +30,7 @@
 
 #include <string.h>
 #include <assert.h>
+#include <errno.h>
 
 struct cx_hash_map_element_s {
     /** A pointer to the next element in the current bucket. */
@@ -451,6 +452,10 @@
     if (map->collection.size > ((hash_map->bucket_count * 3) >> 2)) {
 
         size_t new_bucket_count = (map->collection.size * 5) >> 1;
+        if (new_bucket_count < hash_map->bucket_count) {
+            errno = EOVERFLOW;
+            return 1;
+        }
         struct cx_hash_map_element_s **new_buckets = cxCalloc(
                 map->collection.allocator,
                 new_bucket_count, sizeof(struct cx_hash_map_element_s *)

mercurial