...
For characters in the basic character set, it doesn't matter does not matter which data type is used, except for type compatibility. Consequently, it is best to use plain char
for character data for compatibility with standard string-handling functions.
In most cases, the only portable operators on plain char
types are assignment and equality operators (=
, ==
, !=
). An exception is the translation to and from digits. For example, if the char
c
is a digit, c - '0'
is a value between 0 and 9.
...
The following noncompliant code example simply shows the standard string-handling function strlen()
being called with a plain character string, a signed character string, and an unsigned character string. The strlen()
functions function takes a single argument of type const char
*.
...
Compiling at high warning levels in compliance with recommendation MSC00-C. Compile cleanly at high warning levels causes warnings to be issued when
- converting from
unsigned char[]
toconst char *
whenchar
is signed. - converting from
signed char[]
toconst char *
whenchar
is defined to be unsigned.
Casts are required to eliminate these warnings, but excessive casts can make code difficult to read and hide legitimate warning messages.
...
Tool | Version | Checker | Description | |||||||
---|---|---|---|---|---|---|---|---|---|---|
Section | Fortify SCA section | V. 5.0 |
| Section | Can detect violations of this rule with CERT C Rule Pack, except cases involving | |||||
Section | EDG |
|
| section | ||||||
Compass/ROSE |
|
|
| section|||||||
ECLAIR section |
| Section | charsgnd section | Fully Implementedimplemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
CERT C++ Secure Coding Standard: STR04-CPP. Use plain char for characters in the basic character set
ISO/IEC 9899:19992011 Section 6.2.5, "Types"
MISRA Rule 6.1, "The plain char type shall be used only for the storage and use of character values"
...