title: Reading line from file causes crash
body: <p>I'm trying to read a line from a file character by character and place the characters in a string; here' my code:</p>
  
  <pre><code>char *str = "";
  size_t len = 1; /* I also count the terminating character */
  
  char temp;
  while ((temp = getc(file)) != EOF)
  {
      str = realloc(str, ++len * sizeof(char));
      str[len-2] = temp;
      str[len-1] = '\0';
  }
  </code></pre>
  
  <p>The program crashes on the <code>realloc</code> line. If I move that line outside of the loop or comment it out, it doesn't crash. If I'm just reading the characters and then sending them to stdout, it all works fine (ie. the file is opened correctly). Where's the problem?</p>