Fix bug where an outdate node is returned.

If htab_add_core added a node that happened to push the htab past its load
factor, it would return a pointer to where the added node was *before* the
rehash. Now it does not do this.
This commit is contained in:
Payton Turnage 2014-01-14 20:54:31 -05:00
parent 584217a142
commit daa02f5082

View file

@ -89,6 +89,11 @@ static void htab_rehash(tvm_htab_t *orig, unsigned int size)
static tvm_htab_node_t *htab_add_core(tvm_htab_t *htab, const char *k)
{
/* Increase bucket count and rehash if the
load factor is too high */
if((float)++htab->num_nodes / htab->size > HTAB_LOAD_FACTOR)
htab_rehash(htab, htab->num_nodes * 2);
int hash = htab_hash(k, htab->size);
tvm_htab_node_t *node = htab->nodes[hash];
tvm_htab_node_t *prev = NULL;
@ -114,11 +119,6 @@ static tvm_htab_node_t *htab_add_core(tvm_htab_t *htab, const char *k)
node->next = NULL;
/* Increase bucket count and rehash if the
load factor is too high */
if((float)++htab->num_nodes / htab->size > HTAB_LOAD_FACTOR)
htab_rehash(htab, htab->num_nodes * 2);
return node;
}