...
The header
<ctype.h>
declares several functions useful for classifying and mapping characters. In all cases the argument is anint
, the value of which shall be representable as anunsigned char
or shall equal the value of the macroEOF
. 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 | ||||||||
PRQA QA·CQA-C |
| Fully implemented |
...
MITRE CWE: CWE-686, "Function call with incorrect argument type"
Bibliography
[Kettlewell 2002] Section 1.1, "<ctype.h
> and characters types"
...