summary refs log tree commit diff
diff options
context:
space:
mode:
authorWormHeamer2025-03-04 08:55:36 -0500
committerWormHeamer2025-03-04 08:55:36 -0500
commit3ea6826e8e4ea39d0521a3a44ccbad322eaed73c (patch)
tree24f0e80f634c9d990c9480df9ca61943debcb062
parent140a47b2ed88af49cea5c781a0eb296fcdf52a94 (diff)
make sure to AND chars of key with 255 to prevent sign extension
-rw-r--r--shash.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/shash.h b/shash.h
index 69f5d61..e039ebb 100644
--- a/shash.h
+++ b/shash.h
@@ -43,7 +43,7 @@ StrHashEntry *shash_find(StrHashTable *h, strv_t key);
 #define FNV_OFFSET_BASIS (hash_t)14695981039346656037LU
 hash_t shash(strv_t s) {
 	hash_t h = FNV_OFFSET_BASIS;
-	for (size_t i = 0; i < s.n; i++) h = (h ^ s.s[i]) * FNV_64_PRIME;
+	for (size_t i = 0; i < s.n; i++) h = (h ^ (s.s[i] & 255)) * FNV_64_PRIME;
 	return h;
 }