0

I've been puttering around with speller for a couple of weeks now. It now works, returns the correct spelled words and decently quickly, but it doesn't like the code for load.

Here, Valgrind gives an error: ==4197== Conditional jump or move depends on uninitialised value(s)

Help50 states:

Looks like you're trying to use a variable that might not have a value? Take a closer look at line 107 of dictionary.c.

Here's the line:

 if (pointer->children[index] == NULL) //here's what valgrind doesn't like
        {
            pointer->children[index] = malloc(sizeof(node));
            pointer = pointer->children[index];
        }
        else
        {
            pointer = pointer->children[index];
        }
    }
pointer->is_word = true;
count++;

Any pointers?

1

This pointer->children[index] is uninitalized because it's never been set to anything. From man malloc:

The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized.

When you declare pointer, you could use calloc instead (see the same man page); that initializes the memory. Or you could iterate through the children array and set each index to NULL.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .