diff -r 006e076a8db7 -r 4983b6a34996 src/hash_map.c --- a/src/hash_map.c Fri Dec 19 17:37:17 2025 +0100 +++ b/src/hash_map.c Fri Dec 19 17:41:53 2025 +0100 @@ -400,6 +400,13 @@ cx_hash_map_iterator, }; +static int cx_map_cmpfunc2_safe_memcmp(const void *a, const void *b, void *c) { + // it is not safe to store a pointer to the size in the list + // because the entire list structure might get reallocated + size_t elem_size = (size_t)(uintptr_t)c; + return memcmp(a, b, elem_size); +} + CxMap *cxHashMapCreate( const CxAllocator *allocator, size_t itemsize, @@ -432,8 +439,8 @@ if (itemsize > 0) { map->base.collection.elem_size = itemsize; - map->base.collection.advanced_cmp = cx_ccmp_memcmp; - map->base.collection.cmp_data = &map->base.collection.elem_size; + map->base.collection.advanced_cmp = cx_map_cmpfunc2_safe_memcmp; + map->base.collection.cmp_data = (void*)(uintptr_t)itemsize; } else { map->base.collection.elem_size = sizeof(void *); map->base.collection.store_pointer = true;