summaryrefslogtreecommitdiff
path: root/source3/lib/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/hash.c')
-rw-r--r--source3/lib/hash.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/source3/lib/hash.c b/source3/lib/hash.c
index 6b7a8476b1..c7b1493b4c 100644
--- a/source3/lib/hash.c
+++ b/source3/lib/hash.c
@@ -28,7 +28,7 @@
#include "includes.h"
static BOOL enlarge_hash_table(hash_table *table);
-static int primes[] =
+static unsigned primes[] =
{17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411};
/****************************************************************************
@@ -47,9 +47,9 @@ static int primes[] =
****************************************************************************
*/
-BOOL hash_table_init(hash_table *table, int num_buckets, compare_function compare_func)
+BOOL hash_table_init(hash_table *table, unsigned num_buckets, compare_function compare_func)
{
- int i;
+ unsigned i;
ubi_dlList *bucket;
table->num_elements = 0;
@@ -118,7 +118,7 @@ static hash_element *hash_chain_find(hash_table *table, ubi_dlList *hash_chain,
{
hash_element *hash_elem;
ubi_dlNodePtr lru_item;
- int i = 0;
+ unsigned int i = 0;
for (hash_elem = (hash_element *)(ubi_dlFirst(hash_chain)); i < hash_chain->count;
i++, hash_elem = (hash_element *)(ubi_dlNext(hash_elem))) {
@@ -171,6 +171,7 @@ hash_element *hash_insert(hash_table *table, char *value, char *key)
hash_element *hash_elem;
ubi_dlNodePtr lru_item;
ubi_dlList *bucket;
+ size_t string_length;
/*
* If the hash table size has not reached the MAX_HASH_TABLE_SIZE,
@@ -204,12 +205,13 @@ hash_element *hash_insert(hash_table *table, char *value, char *key)
* string.
*/
- if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + strlen(key)))) {
+ string_length = strlen(key);
+ if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + string_length))) {
DEBUG(0,("hash_insert: malloc fail !\n"));
return (hash_element *)NULL;
}
- safe_strcpy((char *) hash_elem->key, key, strlen(key)+1);
+ safe_strcpy((char *) hash_elem->key, key, string_length);
hash_elem->value = (char *)value;
hash_elem->bucket = bucket;
@@ -299,7 +301,7 @@ static BOOL enlarge_hash_table(hash_table *table)
void hash_clear(hash_table *table)
{
- int i;
+ unsigned int i;
ubi_dlList *bucket = table->buckets;
hash_element *hash_elem;
for (i = 0; i < table->size; bucket++, i++) {