diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-14 00:10:15 -0800 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-14 00:10:15 -0800 |
commit | c5593142f750bc440b2d6a0952deaeb769bc6c57 (patch) | |
tree | af80dbf961ff01b337b39d1c353e90a740db3677 /nasmlib | |
parent | 628c93f0dca79375ccb3e6ac56dbddad57e11764 (diff) | |
download | nasm-c5593142f750bc440b2d6a0952deaeb769bc6c57.tar.gz |
hashtbl: fix errors in hash_iterate() and hash_free()
Both of these functions were apparently subtly broken after the revamp
to the new interfaces.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'nasmlib')
-rw-r--r-- | nasmlib/hashtbl.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/nasmlib/hashtbl.c b/nasmlib/hashtbl.c index a6cbdb19..b89b0200 100644 --- a/nasmlib/hashtbl.c +++ b/nasmlib/hashtbl.c @@ -226,10 +226,10 @@ void **hash_add(struct hash_insert *insert, const void *key, void *data) } /* - * Iterate over all members of a hash set. For the first call, - * iter->node should be initialized to NULL. Returns a pointer to - * a struct hash_node representing the current object, or NULL - * if we have reached the end of the hash table; this is the + * Iterate over all members of a hash set. For the first call, iter + * should be as initialized by hash_iterator_init(). Returns a struct + * hash_node representing the current object, or NULL if we have + * reached the end of the hash table. * * Calling hash_add() will invalidate the iterator. */ @@ -239,14 +239,13 @@ const struct hash_node *hash_iterate(struct hash_iterator *iter) const struct hash_node *cp = iter->next; const struct hash_node *ep = head->table + head->size; - /* For an empty table, np == ep == NULL */ + /* For an empty table, cp == ep == NULL */ while (cp < ep) { - const struct hash_node *np = cp+1; - if (np->key) { - iter->next = np; + if (cp->key) { + iter->next = cp+1; return cp; } - cp = np; + cp++; } iter->next = head->table; @@ -262,10 +261,8 @@ const struct hash_node *hash_iterate(struct hash_iterator *iter) void hash_free(struct hash_table *head) { void *p = head->table; - if (likely(p)) { - head->table = NULL; - nasm_free(p); - } + memset(head, 0, sizeof *head); + nasm_free(p); } /* |