Tim Sarbin
Tim Sarbin

Reputation: 81

Valgrind "Conditional jump or move depends on uninitialised value(s)" Error

I am getting many errors with valgrind saying "Conditional jump or move depends on uninitialized value(s)".

Below is the one of the blocks. All of them are similar:

vasm_sourceline_info_t* line = asmState->firstLine;
if (line == NULL) return;
while ((line = line->next) != NULL)
{
   printf ("[%s(%i)] %s\n", line->fileName, line->lineNumber, line->data);
}

The error itself is on the while() line. vasm_sourceline_info is a doubly linked list structure. The code ~works~ but this error is worrying. Is there something else in code stomping on memory, or is the above function flawed in some way?

Upvotes: 8

Views: 29275

Answers (2)

Matt Joiner
Matt Joiner

Reputation: 118500

Compile with optimizations OFF (-O0). Run valgrind with --track-origins=yes to determine the source of the errors. See here for more.

Upvotes: 14

sepp2k
sepp2k

Reputation: 370142

There's nothing wrong with the code per se, but if one of the lines' next field has not been initialized (presumably the last line's next field), that would explain the message.

Upvotes: 6

Related Questions