1
votes

Valgrind states me two errors that I can not solve. I get a "Conditional jump or move depends on uninitialised value" error message in the following function unplug_set. Is it because of the NULL check? The function should unplug on element from an double linked list.

void unplug_set(set * set_to_unplug){
        set * last_set = set_to_unplug->last;
        set * next_set = set_to_unplug->next;
        set_to_unplug->next = NULL;
        set_to_unplug->last = NULL;
148     if(last_set == NULL && next_set == NULL){ // only one element left
          ordered_by_score_set[set_to_unplug->weight] = NULL;
150     }else if(last_set == NULL){ // first set
          next_set->last = NULL;
          ordered_by_score_set[set_to_unplug->weight] = next_set;
        } else if (next_set == NULL) { // last set
          last_set->next = NULL;
        } else { // set in the middle
          last_set->next = next_set;
        next_set->last = last_set;
       }
}

The Valgrind command:

valgrind --dsymutil=yes --track-origins=yes ./set_program

Output:

==45085== Conditional jump or move depends on uninitialised value(s)
==45085==    at 0x100001A2C: unplug_set(set*) (:148)
                          ...
==45085==    by 0x100001294: main (Main.cpp:81)
==45085==  Uninitialised value was created by a heap allocation
==45085==    at 0xC713: malloc (vg_replace_malloc.c:274)
==45085==    by 0x63346: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==45085==    by 0x100001E0C: add_set(int, int, unsigned int const*, unsigned short const*, int, unsigned int const*) (:57)
==45085==    by 0x10000127E: main (Main.cpp:39)
==45085==
==45085== Conditional jump or move depends on uninitialised value(s)
==45085==    at 0x100001A60: unplug_set(set*) (:150)
                          ...
==45085==    by 0x100001294: main (Main.cpp:81)
==45085==  Uninitialised value was created by a heap allocation
==45085==    at 0xC713: malloc (vg_replace_malloc.c:274)
==45085==    by 0x63346: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==45085==    by 0x100001E0C: add_set(int, int, unsigned int const*, unsigned short const*, int, unsigned int const*) (:57)
==45085==    by 0x10000127E: main (Main.cpp:39)
1
Use the valgrind option --track-origins=yesuser195488
It sounds like either set instances don't initialise all their members when allocated or list manipulation code doesn't always correctly update next/prev pointers. Can you post a full, small example which demonstrates this problem?simonc
I like how every single related link is basically the same title.chris
@simonc oh this could be possible. I check thismartin s
@simonc that the solution. Thank you a lot. I have to get better with valgrind.martin s

1 Answers

0
votes

set_to_unplug argument value is initialized by its constructor using new operator. If no initialization in the constructor, then you have the reason why valgrind complain.

We dont have enough information to answer your problem. post how this function is used. and how the argument value is initialized.