hashtable_add now checks input parameter and returns with zero (indicating that no elements were added) if hashsize is zero. Caused floating point exception.

This commit is contained in:
vraatikka 2013-08-05 15:01:36 +03:00
parent ef1c514489
commit bc6fe8f6ef

View File

@ -167,9 +167,14 @@ hashtable_memory_fns(HASHTABLE *table, HASHMEMORYFN copyfn, HASHMEMORYFN freefn)
int
hashtable_add(HASHTABLE *table, void *key, void *value)
{
int hashkey = table->hashfn(key) % table->hashsize;
HASHENTRIES *entry;
int hashkey;
HASHENTRIES *entry;
if (table->hashsize <= 0) {
return 0;
} else {
hashkey = table->hashfn(key) % table->hashsize;
}
hashtable_write_lock(table);
entry = table->entries[hashkey % table->hashsize];
while (entry && table->cmpfn(key, entry->key) != 0)