title: AddressSanitiser: SEGV on unknown address
body: <p>I am getting the error </p>
  
  <blockquote>
    <p>SEGV on unknown address</p>
  </blockquote>
  
  <p>while running my program. I am pretty sure it is coming from <code>fgets()</code> but i am not quite sure why. Before this, I was using <code>scanf()</code> and it was working fine. the input was going into the array just fine, but I had to use <code>fgets()</code> for the program to detect an input of a new line. Can anyone help me understand why I am getting this error and suggest a way to fix this problem?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void) {
  
      int x = -1;
      int y = -1;
  
      scanf("%d %d", &amp;x, &amp;y);
  
      if (x &lt;= 0 || y &lt;= 0) {
          printf("Cannot decode\n");
          return 1;
      }
  
      char *temp = 0;
      int v[x][y];
  
      for (int t=0; t &lt; y; t++) {
          for(int i=0; i &lt; x; i++) {
  
              if (fgets(temp, x, stdin)) {
                  v[i][t] = atoi(temp);
              }
          }
      }
  
      // To test array
      int c, o;
      for(o=0; o &lt; x; o++) {
          for(c=0; c &lt; y; c++) {
              printf("%d", v[c][o]);
  
          }
          printf("\n");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Error code:</p>
  
  <pre><code>ASAN:DEADLYSIGNAL
  =================================================================
  ==19==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fcaaf49d4ab bp 0x
  000000000001 sp 0x7ffc84b842b8 T0)
  ==19==The signal is caused by a WRITE memory access.
  ==19==Hint: address points to the zero page.
  #0 0x7fcaaf49d4aa in __memmove_avx_unaligned_erms (/usr/lib/libc.so.6+0x1574aa)
  #1 0x7fcaaf3b4708 in __GI__IO_getline_info (/usr/lib/libc.so.6+0x6e708)
  #2 0x7fcaaf3b353c in fgets (/usr/lib/libc.so.6+0x6d53c)
  #3 0x5001f4 in main /home/nonogram.c:39:11
  #4 0x7fcaaf366f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)
  #5 0x4187d9 in _start (/home/nonogram+0x4187d9)
  
  AddressSanitizer can not provide additional info.
  SUMMARY: AddressSanitizer: SEGV (/usr/lib/libc.so.6+0x1574aa) in __memmove_avx_unaligned_erms
  ==19==ABORTING
  </code></pre>