Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 287
Tim Sarbin Avatar asked Nov 06 '10 16:11

Tim Sarbin


2 Answers

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

like image 69
Matt Joiner Avatar answered Sep 29 '22 14:09

Matt Joiner


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.

like image 43
sepp2k Avatar answered Sep 29 '22 12:09

sepp2k