From 3fde235ab7c8f031dfbbd1763e42c74a59f979ee Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Tue, 15 Sep 2015 10:12:07 -0400 Subject: [PATCH] fixing string copy action for hash table insertion --- src/hash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hash.c b/src/hash.c index 4323f01..453c41b 100755 --- a/src/hash.c +++ b/src/hash.c @@ -53,6 +53,7 @@ ENHashTable *ENHashTableCreate() int ENHashTableInsert(ENHashTable *ht, char *key, int data) { + size_t len; unsigned int i = _enHash(key); ENHashEntry *entry; if ( i >= ENHASHTABLEMAXSIZE ) { @@ -62,7 +63,9 @@ int ENHashTableInsert(ENHashTable *ht, char *key, int data) if (entry == NULL) { return(0); } - entry->key = key; + len = strlen(key) + 1; + entry->key = calloc(len, sizeof(char)); + strlcpy(entry->key, key, len); entry->data = data; entry->next = ht[i]; ht[i] = entry;