title: strncpy leading to segmentation fault
body: <p>I am just messing around with strncpy.</p>
  
  <p>My program looks like this </p>
  
  <pre><code>typedef struct
  {
      char from_str[10];
  }test;
  
  main ()
  {
  
      test     s1;
      memset(&amp;s1,0,sizeof(test));
      char       src[10]="himansh";
      char       dest[10];
  
      memset(dest,0,10);
      src[3]='\0';
  
      printf("src is %s and strlen is %d \n",
              src,strlen(src));
  
      fflush(stdout);
  
      strncpy(s1.from_str,src,100);
  
      printf("s1.from_str is %s , src is %s \n",
              s1.from_str,src);
      return 1;
  
  }
  </code></pre>
  
  <p>Here before I do strncpy I have added a "\0" character in "src" string, length of "src" string becomes 3 , destination array is of size 10 .But in strncpy I have put number of bytes to be copied as 100.</p>
  
  <p>This means my source string is NULL terminated. Now strncpy like any string function should try to copy only 3 bytes even if the number of bytes I provide is more than 3 (in this case 100). It does that, but I get a segmentation fault too.</p>
  
  <p>My result is shown below</p>
  
  <pre><code>src is him and strlen is 3
  s1.from_str is him , src is him
  Segmentation fault (core dumped)
  </code></pre>
  
  <p>Why is this segmentation fault happening over here.</p>
  
  <p>Can any one help me out here.</p>