From 27a090e704eca2b8cbcf477bb589974718cbd703 Mon Sep 17 00:00:00 2001 From: Payton Turnage Date: Tue, 14 Jan 2014 00:51:42 -0500 Subject: [PATCH] Remove assumption that node is in the bottom of the bucket. This is the last remaining instance of this assumption. --- libtvm/tvm_htab.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libtvm/tvm_htab.c b/libtvm/tvm_htab.c index 470e41f..635d3c3 100644 --- a/libtvm/tvm_htab.c +++ b/libtvm/tvm_htab.c @@ -127,8 +127,19 @@ int htab_add(tvm_htab_t *htab, const char *k, int v) int htab_add_str(tvm_htab_t *htab, const char *key, const void *valptr, int len) { int hash = htab_add(htab, key, 0); - htab->nodes[hash]->valptr = calloc(len, sizeof(char)); - memcpy(htab->nodes[hash]->valptr, valptr, len); + int found = 0; + tvm_htab_node_t *node = htab->nodes[hash]; + + while (node && !found) + { + if (!strcmp(node->key, key)) + found = 1; + else + node = node->next; + } + + node->valptr = calloc(len, sizeof(char)); + memcpy(node->valptr, valptr, len); return hash; }