Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
char buf[BUFSIZ + 1];

if (fgets(buf, sizeof(buf), fp)) {
  buf[strlen(buf) - 1] = '\0';
}
else {
  /* Handle error condition */
}

However, if the last character in buf is not a newline, this code overwrites an otherwise-valid character.

...