title: try to buffer overflow value allocated by malloc()
body: <p>I'm a bit confused about malloc() function.</p>
  
  <p>if <code>sizeof(char)</code> is <strong>1</strong> <code>byte</code> and the <code>malloc()</code> function accepts N bytes in argument to allocate, then if I do:</p>
  
  <pre><code>char* buffer = malloc(3);
  </code></pre>
  
  <p>I allocate a buffer that can to store 3 characters, right?</p>
  
  <pre><code>char* s = malloc(3);
  int i = 0;
  while(i &lt; 1024) { s[i] = 'b'; i++; }
  s[i++] = '$';
  s[i] = '\0';
  printf("%s\n",s);
  </code></pre>
  
  <p>it works fine. and stores 1024 <code>b's</code> in <code>s</code>.</p>
  
  <pre><code>bbbb[...]$
  </code></pre>
  
  <p>why doesn't the code above cause a buffer overflow? Can anyone explain?</p>