title: Dynamic string without realloc
body: <p>I have this string malloced one byte:</p>
  
  <pre><code>char * word = malloc(sizeof(char));
  </code></pre>
  
  <p>I have another string <code>source.content</code>. The first few characters of this string needs to be copied to <code>word</code> and I use a loop to do the work:</p>
  
  <pre><code>for (int i = 0; isalnum(source.content[0]); ++i)
  {
      word[i] = source.content[0];
      source.content += 1;
  }
  </code></pre>
  
  <p>After the loop, I terminate <code>word</code>:</p>
  
  <pre><code>word[strlen(token.value)-1] = '\0';
  </code></pre>
  
  <p>My question is, why does the program above work when I copied more than 1 character to <code>word</code> even though it's only malloced for 1 character? When I realloaced an additional byte every loop, it does the same thing just slower.</p>