title: Valgrind: conditional jump or move depends on uninitialised value
body: <p>I have the following c file named main.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define NUM_CHAR 20
  
  int main(void) {
      char command_line[NUM_CHAR + 2]; /* Command line string includes the new line character ('\n') and a null character ('\0')  */
      while (1) {
          if (fgets(command_line, sizeof(command_line), stdin) == NULL) { /*This function reads up to sizeof(command_line)-1 characters, or until it encounters the new line character. The function adds '\0' to the end of the array */
              perror("Error: standard function fgets has failed");
              break;
          }
  
          if (command_line[sizeof(command_line) - 2] != '\n' &amp;&amp; strlen(
                  command_line) == NUM_CHAR + 1) { /*# of characters (excluding '\n') in command_line is &lt;=num_char iff the condition takes place. */
              printf(
                      "Error: command length must be less than or equal     to %d characters\n",
                  NUM_CHAR);
          while (getchar() != '\n') {
          } /* read the remaining characters */
          continue;/* continue with  while(1) loop */
          }
  
          printf("%s",command_line);
  
          if (command_line[0] == 'Q') {
              break;
          }
      }
    return 0;
  }
  </code></pre>
  
  <p>a text file named input with the following line:</p>
  
  <pre><code> Quit
  </code></pre>
  
  <p>This is what I got after running valgrind in the terminal (the name of the program is also main):</p>
  
  <pre><code>student@student-VirtualBox:~/workspace/tests$ valgrind --track-origins=yes --leak-check=full ./main &lt; input
  ==2649== Memcheck, a memory error detector
  ==2649== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
  ==2649== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
  ==2649== Command: ./main
  ==2649== 
  ==2649== Conditional jump or move depends on uninitialised value(s)
  ==2649==    at 0x8048542: main (in /home/student/workspace/tests/main)
  ==2649==  Uninitialised value was created by a stack allocation
  ==2649==    at 0x80484FA: main (in /home/student/workspace/tests/main)
  ==2649== 
  Quit
  ==2649== 
  ==2649== HEAP SUMMARY:
  ==2649==     in use at exit: 0 bytes in 0 blocks
  ==2649==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
  ==2649== 
  ==2649== All heap blocks were freed -- no leaks are possible
  ==2649== 
  ==2649== For counts of detected and suppressed errors, rerun with: -v
  ==2649== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 11 from 6)
  </code></pre>
  
  <p>By the way, I compiled this code with optimizations OFF (<code>-O0</code>).
  I have 2 questions:</p>
  
  <p>What is the cause for the error: Conditional jump or move depends on uninitialised value(s) ?</p>
  
  <p>Why doesn't valgrind show the line number of the line that caused this error ?</p>