Commit 348c9b2f authored by mofaph's avatar mofaph

bugfix: test/test_hashtable segment fault

In zc_hashtable.c, zc_hashtable_remove() and zc_hashtable_del() didn't check the
argument pass to it.  So, if pass NULL to them, they will dereference it, and if
we are lucky, it will segment fault.

This commit fix that problem.
parent 5d6b3046
......@@ -64,6 +64,11 @@ void zc_hashtable_del(zc_hashtable_t * a_table)
zc_hashtable_entry_t *p;
zc_hashtable_entry_t *q;
if (!a_table) {
zc_error("a_table[%p] is NULL, just do nothing", a_table);
return;
}
for (i = 0; i < a_table->tab_size; i++) {
for (p = (a_table->tab)[i]; p; p = q) {
q = p->next;
......@@ -231,6 +236,11 @@ void zc_hashtable_remove(zc_hashtable_t * a_table, const void *a_key)
zc_hashtable_entry_t *p;
unsigned int i;
if (!a_table || !a_key) {
zc_error("a_table[%p] or a_key[%p] is NULL, just do nothing");
return;
}
i = a_table->hash(a_key) % a_table->tab_size;
for (p = (a_table->tab)[i]; p; p = p->next) {
if (a_table->equal(a_key, p->key))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment