Weak typing in C allows type casting memory to different types. Because the internal representation of most types is system dependent, applying operations intended for data of one type to data of a different type will likely yield non-portable nonportable code and produce unexpected results.
...
Bit fields can be used to allow flags or other integer values with small ranges to be packed together to save storage space. Bit fields can improve the storage efficiency of structures. Compilers typically allocate consecutive bit-field structure members into the same int
-sized storage, as long as they fit completely into that storage unit. However, the order of allocation within a storage unit is implementation-defined. Some implementations are "right-to-left": the first member occupies the low-order position of the storage unit. Others are "left-to-right": the first member occupies the high-order position of the storage unit. Calculations that depend on the order of bits within a storage unit may produce different results on different implementations.
...
Making invalid assumptions about the type of type-cast data, especially bit - fields, can result in unexpected data values.
...
Tool | Version | Checker | Description | section||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
| Section | Can detect violations of this recommendation. Specifically, it reports violations if A pointer
| |||||||
Section | |
| Section | 94 S | Fully Implementedimplemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this recommendation on the CERT website.
...
CERT C++ Secure Coding Standard: EXP11-CPP. Do not apply operators expecting one type to data of an incompatible type
ISO/IEC 9899:1999 Section 2011 Section 6.7.2, "Type specifiers"
ISO/IEC TR 17961 (Draft) Accessing an object through a pointer to an incompatible type [ptrcomp]
ISO/IEC TR 24772 "STR Bit Representationsrepresentations"
MISRA Rule 3.5
Bibliography
...