fixing string copy action for hash table insertion

This commit is contained in:
Sam Hatchett
2015-09-15 10:12:07 -04:00
parent 2c46a002ba
commit 3fde235ab7

View File

@@ -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;