Note that there are some explanatory texts on larger screens.

plurals
  1. POvalgrind shows an error when running a comparison
    primarykey
    data
    text
    <p>I have the following function</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include "block.h" bool block_equal(const struct block *block1, const struct block *block2) { if ((block1 == NULL) ^ (block2 == NULL)) return false; else if (block1 == NULL &amp; block2 == NULL) return true; else { // ... Some stuff } } </code></pre> <p>When I run it with a pointer to an initialized <code>struct block</code> and <code>NULL</code>, valgrind shows this error (line 6 is the first comparison):</p> <pre><code>==24444== Conditional jump or move depends on uninitialised value(s) ==24444== at 0x402E34: block_equal (block.c:6) ==24444== by 0x4025D3: test_chunks_write (test_chunks.c:22) ==24444== by 0x4E31FE8: ??? (in /usr/lib/libcunit.so.1.0.1) ==24444== by 0x4E323C6: ??? (in /usr/lib/libcunit.so.1.0.1) ==24444== by 0x4E326E7: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1) ==24444== by 0x401627: main (tests.c:15) </code></pre> <p>EDIT: Here is the call of <code>block_equal</code>:</p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;CUnit/CUnit.h&gt; #include "../chunks.h" #include "../block.h" void test_chunks_write(void) { struct block *block1, *block2; block1 = malloc(sizeof(struct block)); block2 = malloc(sizeof(struct block)); block1-&gt;type = BLOCK_WOOD; block2-&gt;type = BLOCK_STONE; chunks *chunks = chunks_empty(); coordinates coord1; coordinates coord2; for (int i=0; i&lt;SPACE_DIMENSION; i++) { coord1[i] = i+1; coord2[i] = 2*i+5; } chunks_write_data(&amp;chunks, coord1, block1); CU_ASSERT(block_equal(block1, chunks_select_data(chunks, coord1))) CU_ASSERT_FALSE(block_equal(block2, chunks_select_data(chunks, coord1))) struct block* block3 = chunks_select_data(chunks, coord2); /////////////////////////////////////////////////////////////////////////////////////////////// // According to the debugger, at this point block2 is 0x605600 and block3 is 0x0 CU_ASSERT_FALSE(block_equal(block2, block3)) // ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload