diff -r 3f3a0d19db58 -r d566bd3e6af8 src/hash_map.c --- a/src/hash_map.c Fri Aug 12 16:47:11 2022 +0200 +++ b/src/hash_map.c Fri Aug 12 16:48:59 2022 +0200 @@ -86,7 +86,12 @@ elm = elm->next; } - if (elm == NULL || elm->key.hash != hash) { + if (elm != NULL && elm->key.hash == hash) { + // overwrite existing element + elm->data = value; + } else { + // insert new element + struct cx_hash_map_element_s *e = cxMalloc(allocator, sizeof(struct cx_hash_map_element_s)); if (e == NULL) { return -1; @@ -116,9 +121,6 @@ // increase the size map->size++; - } else { - // (elem != NULL && elem->key.hash == hash) - overwrite value of existing element - elm->data = value; } return 0;