title: Calling memset causes segmentation fault
body: <p>This program causes a seg fault on my UNIX machine. I narrowed the cause down to the <strong>second</strong> call of memset().</p>
  
  <p>Why is this behaviour occurring? The first "chunk" of code is almost the same as the second, isn't it? Why didn't the <strong>first</strong> call of memset segfault if the second one does?</p>
  
  <p>I looked over other threads concerning segfaulting memset calls, but none of them were similar to this.</p>
  
  <p>In case you were wondering why I wrote such a trivial program, it's adapted from another program I've been writing that I was using to teach myself how to apply memcpy() to structures.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct{
      int x;
      char text;
  } FilesStruct;
  
  int
  main(int argc, char** argv)
  {
      FilesStruct *old_dir;
      memset(old_dir,0,sizeof(FilesStruct));
      old_dir-&gt;x = 3;
      old_dir-&gt;text = 'c';
      printf("old dir: %d,%c\n",old_dir-&gt;x,old_dir-&gt;text);
  
      FilesStruct *new_dir;
      memset(new_dir,0,sizeof(FilesStruct));
      new_dir-&gt;x = 7;
      new_dir-&gt;text = 'g';
      printf("new dir: %d,%c\n",new_dir-&gt;x,new_dir-&gt;text);
  
      return 0;
  }
  </code></pre>