X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/4769a870917b98723690aa336d12d0656769528b..2804ceee4ce65d49e9d52d0ed817317c0ac9efdc:/lunaix-os/libs/hash.c diff --git a/lunaix-os/libs/hash.c b/lunaix-os/libs/hash.c index 293ec67..dc1b3cc 100644 --- a/lunaix-os/libs/hash.c +++ b/lunaix-os/libs/hash.c @@ -9,12 +9,15 @@ * @return unsigned int */ uint32_t -strhash_32(unsigned char* str, uint32_t truncate_to) +strhash_32(const 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);