Merge branch 'develop'
This commit is contained in:
@ -184,6 +184,9 @@ hashtable_add(HASHTABLE *table, void *key, void *value)
|
|||||||
int hashkey;
|
int hashkey;
|
||||||
HASHENTRIES *entry;
|
HASHENTRIES *entry;
|
||||||
|
|
||||||
|
if (key == NULL || value == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (table->hashsize <= 0) {
|
if (table->hashsize <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@ -209,8 +212,27 @@ hashtable_add(HASHTABLE *table, void *key, void *value)
|
|||||||
hashtable_write_unlock(table);
|
hashtable_write_unlock(table);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* copy the key */
|
||||||
ptr->key = table->kcopyfn(key);
|
ptr->key = table->kcopyfn(key);
|
||||||
|
|
||||||
|
/* check succesfull key copy */
|
||||||
|
if ( ptr->key == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* copy the value */
|
||||||
ptr->value = table->vcopyfn(value);
|
ptr->value = table->vcopyfn(value);
|
||||||
|
|
||||||
|
/* check succesfull value copy */
|
||||||
|
if ( ptr->value == NULL) {
|
||||||
|
/* remove the key ! */
|
||||||
|
table->kfreefn(ptr->key);
|
||||||
|
|
||||||
|
/* value not copied, return */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ptr->next = table->entries[hashkey % table->hashsize];
|
ptr->next = table->entries[hashkey % table->hashsize];
|
||||||
table->entries[hashkey % table->hashsize] = ptr;
|
table->entries[hashkey % table->hashsize] = ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user