diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-05 12:16:50 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-05 12:17:36 +0100 |
commit | 40b9ca0fdd1283f328ad26f1276259526d2cd861 (patch) | |
tree | 961919202a0639dc75ba77bf3588653cf6e7e4a4 /lib/hashtable.c | |
parent | clean (diff) | |
download | c-hashtable-40b9ca0fdd1283f328ad26f1276259526d2cd861.tar.gz c-hashtable-40b9ca0fdd1283f328ad26f1276259526d2cd861.tar.bz2 c-hashtable-40b9ca0fdd1283f328ad26f1276259526d2cd861.zip |
fix memory bug in hashmap implementation
Diffstat (limited to 'lib/hashtable.c')
-rw-r--r-- | lib/hashtable.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/hashtable.c b/lib/hashtable.c index f9f9873..98d9805 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -79,12 +79,12 @@ int hashtable_put(HashTable ht, char* key, void* val, size_t val_size) { int index = hash(key, ht_impl->capacity); HashTableBucket* bucket = &ht_impl->buckets[index]; - //TODO: reuse the deleted? for (int i = 0; i < bucket->length; ++i) { HashTableData* data = &bucket->data[i]; if (strcmp(data->key, key) == 0) { - data->data = val; + data->data = realloc(data->data, val_size); + memcpy(data->data, val, val_size); data->deleted = 0; return 0; } |