The three types char
, signed char
, and unsigned char
are collectively called the character types. Compilers have the latitude to define char
to have the same range, representation, and behavior as either signed char
or unsigned char
. Irrespective of the choice made, {{char}}is a separate type from the other two and is not compatible with either.
Use plain char
for character data for compatibility with standard string handling functions.
The only permissible operators on plain char types are assignment and equality operators (=, ==, != ).
Non-Compliant Code Example
unsigned char msg[100];
Compliant Solution
char error_msg[100];
Risk Assessment
Rule |
Severity |
Likelihood |
Remediation Cost |
Priority |
Level |
---|---|---|---|---|---|
STR07-A |
1 (low) |
1 (unlikely) |
2 (medium) |
P2 |
L3 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
[[ISO/IEC 9899-1999]] Section 5.2.4.1, "Translation limits"
[[MISRA 04]] Rule 6.1, "The plain char type shall be used only for the storage and use of character values."