Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 recommendation STR00-C. Represent characters using an appropriate type for more information on representing characters.

...

Code Block
bgColor#ccccff
unsigned char c = 200;
int i = 1000;
printf("i/c = %d\n", i/c);

Exceptions

INT07-EX1: Guideline Rule 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.

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

CERT C++ Secure Coding Standard: INT07-CPP. Use only explicitly signed or unsigned char type for numeric values

Bibliography

unmigrated-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]\] TR 24772 "STR Bit Representations"

MISRA Rule \[[MISRA 2004|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 2007|AA. Bibliography#MITRE 07]\] [CWE ID 682|http://cwe.mitre.org/data/definitions/682.html], "Incorrect Calculation"

MITRE CWE: CWE-682, "Incorrect Calculation"

Bibliography

...

INT06-C. Use strtol() or a related function to convert a string token to an integer      04. Integers (INT)