feat: lru eviction policy on page caches
[lunaix-os.git] / lunaix-os / libs / hash.c
index 293ec67bc3bddb6d7a450e09e32009c5f827f4e3..277efb32eaf8370fc8f265ef8038ce4d1960004f 100644 (file)
@@ -9,12 +9,15 @@
  * @return unsigned int
  */
 uint32_t
-strhash_32(unsigned char* str, uint32_t truncate_to)
+strhash_32(char* str, uint32_t truncate_to)
 {
+    if (!str)
+        return 0;
+
     uint32_t hash = 5381;
     int c;
 
-    while (c = *str++)
+    while ((c = *str++))
         hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
 
     return hash >> (HASH_SIZE_BITS - truncate_to);