Versions Compared

Key

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

...

This compliant solution checks to make sure the first character in the buf array is not a NULL before modifying it based on data obtained by the results of strlen().

Code Block
bgColor#ccccff
char buf[1024];

if (fgets(buf, sizeof(buf), fp) != NULL) {
	if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
		buf[strlen(buf) - 1] = '\0';
}

...