...
Use only signed char
and unsigned char
types for the storage and use of numeric values, as this is the only portable way to guarantee the signedness of the character types. See guideline STR00-C. Represent characters using an appropriate type for more information on representing characters.
...
Code Block | ||
---|---|---|
| ||
unsigned char c = 200; int i = 1000; printf("i/c = %d\n", i/c); |
Exceptions
INT07-EX1: Guideline FIO34-C. Use int to capture the return value of character IO functions mentions that certain character IO functions return a value of type int
. Despite being returned in an arithmetic type, the value is not actually numeric in nature so it is acceptable to later store the result into a variable of type char
.
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
INT07-C | medium | probable | medium | P8 | L2 |
Automated Detection
...
Tool | Version | Checker | Description |
---|---|---|---|
|
...
|
|
| ||||||||
|
|
|
|
...
|
...
|
|
|
| ||||||||
|
|
|
|
...
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
Related Guidelines
This rule appears in the C++ Secure Coding Standard as : INT07-CPP. Use only explicitly signed or unsigned char type for numeric values.
Bibliography
Wiki Markup |
---|
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.2.5, "Types" \[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "STR Bit Representations" \[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 6.2, "Signed and unsigned char type shall be used only for the storage and use of numeric values" \[[MITRE 072007|AA. Bibliography#MITRE 07]\] [CWE ID 682|http://cwe.mitre.org/data/definitions/682.html], "Incorrect Calculation" |
...