summaryrefslogtreecommitdiff
path: root/ckcapi-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'ckcapi-util.c')
-rw-r--r--ckcapi-util.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ckcapi-util.c b/ckcapi-util.c
index 80e1b40..ae8c39b 100644
--- a/ckcapi-util.c
+++ b/ckcapi-util.c
@@ -296,7 +296,7 @@ equal_default(const void* a, const void* b)
static HashEntry**
alloc_array(CkCapiHash* ht, size_t max)
{
- return calloc(sizeof(*(ht->array)) * (max + 1), 1);
+ return calloc(1, sizeof(*(ht->array)) * (max + 1));
}
CkCapiHash*
@@ -352,6 +352,7 @@ expand_array(CkCapiHash* ht)
HashEntry** new_array;
size_t new_max;
HashEntry* he;
+ HashEntry* next;
size_t i;
new_max = ht->max * 2 + 1;
@@ -362,7 +363,8 @@ expand_array(CkCapiHash* ht)
for(i = 0; i <= ht->max; ++i)
{
- for(he = ht->array[i]; he; he = he->next)
+ for(he = ht->array[i], next = he ? he->next : NULL;
+ he != NULL; he = next, next = next ? next->next : NULL)
{
unsigned int j = he->hash & new_max;
he->next = new_array[j];
@@ -413,7 +415,6 @@ find_entry(CkCapiHash* ht, const void* key, void* val)
{
/* Key points to external data */
he->key = key;
-
he->next = NULL;
he->hash = hash;
he->val = val;
@@ -442,6 +443,7 @@ ckcapi_hash_set(CkCapiHash* ht, const void* key, void* val)
if(hep && *hep)
{
/* replace entry */
+ (*hep)->key = key;
(*hep)->val = val;
/* check that the collision rate isn't too high */