Why would this give a Use of uninitialised value of size 8

The most likely cause of uninitialized value is that at least one of b->nextU or b->U that you are adding to delta_U is itself uninitialized. That is:

foo = 0;
foo += some_uninitialized_value;
if (foo)  // Valgrind warns here

You would like Valgrind to report when foo becomes uninitialized. Unfortunately, doing so produces too many “false positive” warnings to be practical.

You can insert into your loop calls to VALGRIND_CHECK_MEM_IS_DEFINED (see Valgrind user manual), and Valgrind will signal the exact moment when delta_U becomes undefined.

Leave a Comment