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

后端 未结 2 1202
情书的邮戳
情书的邮戳 2021-01-12 14:05

In my code I have a class named membrane with a function named exciteMod(), a function named decide() and a variable named delta

相关标签:
2条回答
  • 2021-01-12 14:12

    lets say you have t number of values needed to be stored. then use this:

    int *p = (int *) malloc(t*(sizeof(int)+1));
    memset(p,0,t*(sizeof(int)+1));
    
    0 讨论(0)
  • 2021-01-12 14:16

    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.

    0 讨论(0)
提交回复
热议问题