...
This is a similar issue to the signedness of plain char
, discussed in guideline recommendation INT07-C. Use only explicitly signed or unsigned char type for numeric values. A plain int
bit-field that is treated as unsigned will promote to int
, as long as its field width is less than that of int
because int
can hold all values of the original type. This is the same behavior as that of a plain char
treated as unsigned. However, a plain int
bit-field treated as unsigned will promote to unsigned int
, if its field width is the same as that of int
. This difference makes a plain int
bit-field even trickier than a plain char
.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
CERT C++ Secure Coding Standard: INT12-CPP. Do not make assumptions about the type of a plain int bit-field when used in an expression
Bibliography
unmigrated-wiki-markup
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.7.2, "Type specifiers" \[[
ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] TR 24772 "STR Bit Representations" \[[MISRA 2004|AA. Bibliography#MISRA 04]\] Rule
MISRA Rule 12.7
Bibliography
...
INT11-C. Take care when converting from pointer to integer or integer to pointer 04. Integers (INT)