title: Refers to 0 byte(s) beyond last valid byte in prior malloc
body: <p>I seem to overwrite some parts of the memory in my C program unintentionaly. To fix this, I have downloaded DrMemory in good faith it will throw an error informing me about lines where this nastiness happens.<br>
  One of the first errors I ever get is this one:</p>
  
  <pre><code>~~Dr.M~~ Note: @0:00:00.802 in thread 7376
  ~~Dr.M~~ Note: refers to 0 byte(s) beyond last valid byte in prior malloc
  ~~Dr.M~~ Note: prev lower malloc:  0x00c00eb0-0x00c00eb4
  ~~Dr.M~~ Note: instruction: cmp    (%eax) $0x00
  </code></pre>
  
  <p>According to <a href="http://drmemory.org/docs/page_unaddr.html" rel="nofollow">the documantation</a>, it means that I tried to access the last byte of memory I have first allocated. How's that wrong?</p>
  
  <p>Function that triggers the error:</p>
  
  <pre><code>void str_add_char(String* s, const char ch) {
    size_t length = s-&gt;length;
    if(length+1==s-&gt;size) {
      s-&gt;size+=s-&gt;size/2+1;
      s-&gt;c_str = (char*)realloc(s-&gt;c_str, s-&gt;size);  
    }
    s-&gt;c_str[length]=ch;
    s-&gt;c_str[length+1] = 0;
    s-&gt;length++;
  }
  </code></pre>