diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/std/hash_map.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/std/hash_map.c b/src/std/hash_map.c index 7ba1daf..9d8b4c4 100644 --- a/src/std/hash_map.c +++ b/src/std/hash_map.c @@ -44,8 +44,10 @@ void tsl_hash_map_deinit(TslHashMap *self) { static int tsl_hash_map_append_bucket(TslHashMapNode **head_node, uint64_t hash, const TslStringView *key, size_t size, const void *data, void **output) { TslHashMapNode *next_node; uint8_t *node_data = malloc(sizeof(hash) + sizeof(key->size) + key->size + sizeof(size) + size); + if(output) - *output = node_data; + *output = NULL; + if(!node_data) { fprintf(stderr, "Error: hash map append failed. Reason: out of memory\n"); return 0; @@ -54,8 +56,6 @@ static int tsl_hash_map_append_bucket(TslHashMapNode **head_node, uint64_t hash, next_node = malloc(sizeof(TslHashMapNode)); if(!next_node) { free(node_data); - if(output) - *output = NULL; fprintf(stderr, "Error: hash map append failed. Reason: out of memory\n"); return 0; } @@ -72,6 +72,9 @@ static int tsl_hash_map_append_bucket(TslHashMapNode **head_node, uint64_t hash, if(data) memcpy(node_data + sizeof(hash) + sizeof(key->size) + key->size + sizeof(size), data, size); + if(output) + *output = node_data + sizeof(hash) + sizeof(key->size) + key->size + sizeof(size); + next_node->data = node_data; if(*head_node) { next_node->next = (*head_node)->next; |