Uninitialized value was created by a heap allocation

In the updated code you use an uninitialized pointer:

dictionary = malloc(sizeof(node*) * LISTS);

// .... code that does not change dictionary[i] for any i

new_node->next = dictionary[index];   // use uninitialized pointer

As people had wrote already, this will only work if you had pre-set all the pointers to be NULL before entering this loop:

dictionary = malloc(sizeof(node*) * LISTS);
if ( !dictionary ) {
    return false;
}

for (size_t i = 0; i < LISTS; ++i) {
    dictionary[i] = NULL;
}

Leave a Comment