Why does this make use of an uninitialized value of size 8

In my code, I have a class called membrane with a function called exciteMod() , named decide() and a variable called delta_U . The first line of exciteMod() is this->delta_U = 0 . In decide() has the exponent -delta_U ( exp(-this->delta_U) ). that cause the error. Using an uninitialized size value of 8. What can cause this? I have no errors in delta_U that is generated in valgrind.

Edit: Here is the corresponding code segment:

 void membrane::exciteMod(){ this->delta_U = 0; /* Do some stuff which does not directly affect this->delta_U*/ std::tr1::shared_ptr<bead> bit = this->beads.begin(); while (bit != this->nead.end()){ std::tr1::shared_ptr<bead> b = *bit++; //calculate the doubles U and nextU on b, nothing here gives a warning in valgrind, anyhow U and nextU on b are always defined this->delta_U += (b->nextU - b->U); } decide(); } void membrane::decide(){ double r = Prran3() // the random function from numerical recepies double f = - this->delta_U; if (r > exp(f)){ //this gives the warning even though delta_U is valid /*stuff*/ } } 

This is a warning:

== 467 == Using an uninitialized value of size 8
== 467 == at 0x300B00D75D: __ieee754_exp (in / lib64 / libm-2.5.so)
== 467 == by 0x300B022FA3: exp (in / lib64 / libm-2.5.so)
== 467 == by 0x40BB9A: membrane :: solve () (membr.cpp: 813)
== 467 == by 0x40EBB1: membrane :: exciteMod () (membr.cpp: 639)
== 467 == by 0x413994: membrane :: MCstep (int) (membr.cpp: 486)
== 467 == by 0x402767: main (main.cpp: 14)

Edit:
I should have mentioned that the only place I call decide() is inside exciteMod() .

+6
source share
1 answer

The most likely reason for the uninitialized value is that at least one of b->nextU or b->U that you add to delta_U is not initialized itself. I.e:

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

You would like Valgrind to report when foo becomes uninitialized. Unfortunately, this makes too many "false positive" warnings practical.

You can insert a VALGRIND_CHECK_MEM_IS_DEFINED cycle (see Valgrind User Guide ) into your calls, and Valgrind will indicate the exact moment when delta_U becomes undefined.

+9
source

Source: https://habr.com/ru/post/895272/


All Articles