Versions Compared

Key

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

...

In this noncompliant code example, an error flag is set upon fgets() failure.:

Code Block
bgColor#ffcccc
langc
char buf[BUFSIZ];
FILE *file;
/* Initialize file */

if (fgets(buf, sizeof(buf), file) == NULL) {
  /* Set error flag and continue */
}

...

In this compliant solution, buf is set to an empty string if fgets() fails. The equivalent solution for fgetws() would set buf to an empty wide string.:

Code Block
bgColor#ccccff
langc
char buf[BUFSIZ];
FILE *file;
/* Initialize file */

if (fgets(buf, sizeof(buf), file) == NULL) {
  /* Set error flag and continue */
  *buf = '\0';
}

...