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.
Only use signed char
and unsigned char
types for the storage and use of numeric values.
Non-Compliant Code Example
This non-compliant code example :
char i;
Compliant Solution
This problem is easily repaired by explicitly declaring the string
variable as unsigned char
.
unsigned char i;
Risk Assessment
This is a subtle error that results in a disturbingly broad range of potentially severe vulnerabilities.
Rule |
Severity |
Likelihood |
Remediation Cost |
Priority |
Level |
---|---|---|---|---|---|
INT07-A |
2 (medium) |
2 (probable) |
2 (medium) |
P8 |
L2 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
[[ISO/IEC 9899-1999]] Section 6.2.5, "Types"
[[MISRA 04]] Rule 6.2, "signed and unsigned char type shall be used only for the storage and use of numeric values."