src/hash_key.c

changeset 604
056e5f592d84
parent 603
c49104015a6b
child 628
1e2be40f0cb5
--- a/src/hash_key.c	Sun Nov 06 14:46:59 2022 +0100
+++ b/src/hash_key.c	Sun Nov 06 16:07:32 2022 +0100
@@ -30,8 +30,13 @@
 #include <string.h>
 
 void cx_hash_murmur(CxHashKey *key) {
+    unsigned char const *data = key->data.cbytes;
+    if (data == NULL) {
+        /* extension: special value for NULL */
+        key->hash = 1574210520u;
+        return;
+    }
     size_t len = key->len;
-    unsigned char const *data = key->data.cbytes;
 
     unsigned m = 0x5bd1e995;
     unsigned r = 24;
@@ -79,7 +84,7 @@
 CxHashKey cx_hash_key_str(char const *str) {
     CxHashKey key;
     key.data.cstr = str;
-    key.len = str == NULL ? 0 : (1 + strlen(str));
+    key.len = str == NULL ? 0 : strlen(str);
     cx_hash_murmur(&key);
     return key;
 }

mercurial