Versions Compared

Key

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

...

This noncompliant code example can fail because a copy of stdout is being used in the call to fputs().:

Code Block
bgColor#FFCCCC
langc
int main(void) {
  FILE my_stdout = *(stdout);  /* violation */
  if (fputs("Hello, World!\n", &my_stdout) == EOF) {
    /* Handle error */
  }
  return 0;
}

...

In this compliant solution, a copy of the pointer to the FILE object is used in the call to fputs().:

Code Block
bgColor#ccccff
langc
int main(void) {
  FILE *my_stdout = stdout;
  if (fputs("Hello, World!\n", my_stdout) == EOF) {
    /* Handle error */
  }
  return 0;
}

...

ToolVersionCheckerDescription
Compass/ROSE  

Can detect simple violations of this rule.

LDRA tool suite

Include Page
LDRA_V
LDRA_V

591 S

Fully implemented.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...

[ISO/IEC 9899:2011]Section 7.21.3, "Files"

 

...