Versions Compared

Key

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

...

The header <ctype.h> declares several functions useful for classifying and mapping characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.

(See also undefined behavior 113  of Appendix J.)

Compliance with this rule is complicated by the fact that the char data type can, in any implementation, be signed or unsigned.

The following character classification functions are affected:

...

Note: XSI denotes an X/Open System Interfaces Extension to ISO/IEC 9945—POSIX®. The functions are not defined by the C standard.

STR34-C. Cast characters to unsigned char before converting to larger integer sizes is a generalization of this rule.

...

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.

PRQA QA·CQA-C
Include Page
PRQA_V
PRQA_V
 Fully implemented

...

MITRE CWE: CWE-686, "Function call with incorrect argument type"

Bibliography

[Kettlewell 2002] Section 1.1, "<ctype.h> and characters types"

...