Valgrind complains about using conditional jumps that depend on uninitialized bytes
<p>I had this problem appear in a module of a larger program I am working on and here is a small simulation:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

struct node{
    int key;
    vector&lt;int&gt; connections;
};

int main(void){

    int size = 10;
    node *A;

    A=(node*)malloc((size)*sizeof(node));

    int i;
    for(i=0;i&lt;size;i++){
        A[i].key = i;
        if(i%2 == 0) A[i].connections.push_back(i);
    }

    for(i=0;i&lt;size;i++) {
        if(A[i].connections.size() &gt; 0) {
            cout &lt;&lt; A[i].key &lt;&lt; "---" &lt;&lt; A[i].connections.size() &lt;&lt; endl;
        }
    }

    free(A);

    return 0;
}
</code></pre>

<p>This is a small part of what I get when running <code>valgrind ./testCode</code></p>

<pre><code>==30433== Conditional jump or move depends on uninitialised value(s)
==30433==    at 0x400F63: std::vector&lt;int, std::allocator&lt;int&gt; &gt;::push_back(int const&amp;) (stl_vector.h:915)
==30433==    by 0x400DF0: main (testCode.cpp:25)
</code></pre>

<p>from my understanding the problem is that there is an if statement inside the <code>push_back</code> function of the vector that uses some value that is uninitialized. I am not sure what exactly. After playing around, it turns out the problem is that I use <code>malloc</code>. If I use <code>calloc</code> I won't get any warnings at all. The same if I use <code>new</code>. However in all cases the program behaves exactly the same way. What is happening here? Is it safe to use <code>malloc</code> even though I get all these warnings?</p>