fix #200 - key contents not compared in cx_hash_map_put()

Fri, 12 Aug 2022 16:56:41 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 12 Aug 2022 16:56:41 +0200
changeset 575
b05935945637
parent 574
d566bd3e6af8
child 576
ba0c4ff6698e

fix #200 - key contents not compared in cx_hash_map_put()

src/hash_map.c file | annotate | diff | comparison | revisions
--- a/src/hash_map.c	Fri Aug 12 16:48:59 2022 +0200
+++ b/src/hash_map.c	Fri Aug 12 16:56:41 2022 +0200
@@ -86,12 +86,12 @@
         elm = elm->next;
     }
 
-    if (elm != NULL && elm->key.hash == hash) {
+    if (elm != NULL && elm->key.hash == hash && elm->key.len == key.len &&
+        memcmp(elm->key.data.obj, key.data.obj, key.len) == 0) {
         // overwrite existing element
         elm->data = value;
     } else {
-        // insert new element
-
+        // allocate new element
         struct cx_hash_map_element_s *e = cxMalloc(allocator, sizeof(struct cx_hash_map_element_s));
         if (e == NULL) {
             return -1;

mercurial