diff --git a/base/data-struct/hash.c b/base/data-struct/hash.c index 5ef5ed276..d60f28a25 100644 --- a/base/data-struct/hash.c +++ b/base/data-struct/hash.c @@ -59,26 +59,27 @@ static unsigned char _nums[] = { 209 }; -static struct dm_hash_node *_create_node(const char *str, unsigned len) +static struct dm_hash_node *_create_node(const void *key, unsigned len) { struct dm_hash_node *n = malloc(sizeof(*n) + len); if (n) { - memcpy(n->key, str, len); + memcpy(n->key, key, len); n->keylen = len; } return n; } -static unsigned long _hash(const char *str, unsigned len) +static unsigned long _hash(const void *key, unsigned len) { + const unsigned char *str = key; unsigned long h = 0, g; unsigned i; for (i = 0; i < len; i++) { h <<= 4; - h += _nums[(unsigned char) *str++]; + h += _nums[*str++]; g = h & ((unsigned long) 0xf << 16u); if (g) { h ^= g >> 16u; diff --git a/libdm/datastruct/hash.c b/libdm/datastruct/hash.c index 726347ea2..67261f8da 100644 --- a/libdm/datastruct/hash.c +++ b/libdm/datastruct/hash.c @@ -57,26 +57,27 @@ static unsigned char _nums[] = { 209 }; -static struct dm_hash_node *_create_node(const char *str, unsigned len) +static struct dm_hash_node *_create_node(const void *key, unsigned len) { struct dm_hash_node *n = dm_malloc(sizeof(*n) + len); if (n) { - memcpy(n->key, str, len); + memcpy(n->key, key, len); n->keylen = len; } return n; } -static unsigned long _hash(const char *str, unsigned len) +static unsigned long _hash(const void *key, unsigned len) { + const unsigned char *str = key; unsigned long h = 0, g; unsigned i; for (i = 0; i < len; i++) { h <<= 4; - h += _nums[(unsigned char) *str++]; + h += _nums[*str++]; g = h & ((unsigned long) 0xf << 16u); if (g) { h ^= g >> 16u;