Versions Compared

Key

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

...

This noncompliant code example may pass invalid values to the isspace() function.:

Code Block
bgColor#FFcccc
langc
size_t count_preceding_whitespace(const char *s) {
  const char *t = s;

  /* possibly *t < 0 */
  while (*t && isspace(*t)) {
    ++t;
  }
  return t - s;
}

...

This compliant solution casts the character to unsigned char before passing it as an argument to the isspace() function.:

Code Block
bgColor#ccccff
langc
size_t count_preceding_whitespace(const char *s) {
  const char *t = s;

  while (*t && isspace((unsigned char)*t)) {
    ++t;
  }
  return t - s;
}

...

Tool

Version

Checker

Description

Compass/ROSE

  

Could detect violations of this rule by seeing if the argument to a character-handling function (listed above) is not an unsigned char.

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

idb_charplan

Fully implemented.

PRQA QA-C
Include Page
PRQA_V
PRQA_V
special Special case of STR34Fully implemented.

Related Vulnerabilities

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

...