From: David Given Date: Fri, 16 Dec 2016 21:12:28 +0000 (+0100) Subject: Fix crash when enumerating uninitialised hashtables. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5d4c6f1425890d9a7cc39cee7c111f917b5c0c2f;p=ack.git Fix crash when enumerating uninitialised hashtables. --- diff --git a/modules/src/data/hashtable.c b/modules/src/data/hashtable.c index 7c895b5a7..d4dba61db 100644 --- a/modules/src/data/hashtable.c +++ b/modules/src/data/hashtable.c @@ -163,15 +163,12 @@ void* hashtable_pop(struct hashtable* ht) void* hashtable_next(struct hashtable* ht, struct hashtable_iterator* it) { + lazy_init(ht); + while (!it->node) { if (it->bucket == ht->num_buckets) - { - it->key = it->value = NULL; - it->bucket = 0; - it->node = NULL; - return NULL; - } + goto eof; it->node = ht->buckets[it->bucket]; if (it->node) @@ -187,4 +184,10 @@ void* hashtable_next(struct hashtable* ht, struct hashtable_iterator* it) it->bucket++; return it->value; + +eof: + it->key = it->value = NULL; + it->bucket = 0; + it->node = NULL; + return NULL; }