title: Could valgrind complaint about uninitialized values be a false positive?
body: <p>So I've been teaching myself C, and in the hopes of learning how to properly manage memory from the beginning and write better code, I've been running Valgrind on everything. This has helped me with memory leaks, but I can't seem to get rid of this "Conditional jump or move depends on uninitialised value(s)/Uninitialised value was created by a heap allocation" situation, although I've narrowed it down to this block of code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()    
  {  
      char* test = (char*) malloc(3);
      strncpy(test, "123", 2);
      printf("%s\n", test);
      free(test);
      return 0;
  }
  </code></pre>
  
  <p>When I run Valgrind with <code>---track-origins=yes</code>, I get this output:</p>
  
  <pre><code>==91702== Conditional jump or move depends on uninitialised value(s) 
  ==91702==    at 0x100011507: strlen (mc_replace_strmem.c:282)
  ==91702==    by 0x1000AA338: puts (in /usr/lib/libSystem.B.dylib)
  ==91702==    by 0x100000EFA: main (valgrind_test.c:10)
  ==91702==  Uninitialised value was created by a heap allocation
  ==91702==    at 0x100010345: malloc (vg_replace_malloc.c:236)
  ==91702==    by 0x100000EEA: main (valgrind_test.c:8)
  </code></pre>
  
  <p>This seems like a false positive to me, but I'm not confident enough in my own knowledge to write it off as such. Maybe I'm allocating wrong or using strncpy wrong? I'm not sure.</p>
  
  <p>Thanks in advance</p>