title: Understanding behavior of memcpy() with some error examples
body: <p>I'm trying to write implementation of <code>memcpy</code>.
  Here how it looks:</p>
  
  <pre><code>void *ft_memcpy(void *s1, const void *s2, size_t n)
  {
      size_t i;  
      i = 0;
      while (i &lt; n)
      {
          ((unsigned char *)s1)[i] = ((unsigned char *)s2)[i];
          i++;
      }
      return (s1);
  }
  </code></pre>
  
  <p>It works mostly as string.h <code>memcpy</code>, except some error cases:</p>
  
  <pre><code>memcpy(NULL, NULL, 256)
  </code></pre>
  
  <p>original memcpy returns NULL, my version segfault</p>
  
  <pre><code>void    test_memcpy()
  {
      int  array[512] = {0};
      char byte_array[512];
      memcpy(byte_array, array, sizeof(array));
  }
  </code></pre>
  
  <p>Here's original memcpy ends with <code>zsh: abort</code>, my version works ok.
  This cases invoke undefined behavior, but on one system/compiler I guess it should be the same, but it doesn't. Can anybody explain why it differs this way?</p>