Versions Compared

Key

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

...

In this noncompliant code example, more than one character is pushed back on the stream referenced by fp.:

Code Block
bgColor#ffcccc
langc
FILE *fp;
char *file_name;

/* Initialize file_name */

fp = fopen(file_name, "rb");
if (fp == NULL) {
  /* Handle error */
}

/* Read data */

if (ungetc('\n', fp) == EOF) {
  /* Handle error */
}
if (ungetc('\r', fp) == EOF) {
  /* Handle error */
}

/* Continue on */

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect simple violations of this recommendation. In particular, it warns when two calls to ungetc() on the same stream are not interspersed with a file-positioning or file-read function. It cannot handle cases where ungetc() is called from inside a loop.

LDRA tool suite

Include Page
LDRA_V
LDRA_V

83 D

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.7.10, "The ungetc Function"

 

...