Skip to content

Commit

Permalink
Fix bug where an outdate node is returned.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
turnage committed Jan 15, 2014
1 parent 584217a commit daa02f5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions libtvm/tvm_htab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit daa02f5

Please sign in to comment.