...
The C Standard, 6.3.2.3, paragraph 7 [ISO/IEC 9899:20112024], states
A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the referenced the referenced type, the behavior is undefined.
...
If a developer wishes to violate this rule and use undefined behavior, they must not only ensure that the hardware guarantees the behavior of the object code, but they must also ensure that their compiler and compiler optimizations , along with its optimizer, also respect these guarantees.
...
Tool | Version | Checker | Description | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Astrée |
| Supported, but no explicit checkerpointer-cast-alignment | Fully checked | |||||||||||||||||
Axivion Bauhaus Suite |
| CertC-EXP36 | ||||||||||||||||||
CodeSonar |
| LANG.CAST.PC.OBJ | Cast: Object Pointers | |||||||||||||||||
Compass/ROSE | Can detect violations of this rule. However, it does not flag explicit casts to | |||||||||||||||||||
Coverity |
| MISRA C 2004 Rule 11.4 MISRA C 2012 Rule 11.1 MISRA C 2012 Rule 11.2 MISRA C 2012 Rule 11.5 MISRA C 2012 Rule 11.7 | Implemented | |||||||||||||||||
Cppcheck Premium |
| premium-cert-exp36-c | Partially implemented | |||||||||||||||||
| CC2.EXP36 | Fully implemented | ||||||||||||||||||
EDG | ||||||||||||||||||||
GCC |
| Can detect some violations of this rule when the | ||||||||||||||||||
Helix QAC |
| C0326, C3305 C++3033, C++3038 | ||||||||||||||||||
Klocwork |
| MISRA.CAST. | PTR.UNRELATEDOBJ_PTR_TO_ | INTOBJ_PTR.2012 | ||||||||||||||||
LDRA tool suite |
| 94 S, 606 S | Partially implemented | |||||||||||||||||
Parasoft C/C++test |
| CERT_C-EXP36-a | A cast should not be performed between a pointer to object type and a different pointer to object type | Polyspace Bug Finder | ||||||||||||||||
Include Page | Polyspace Bug Finder_V | Polyspace Bug Finder_V | Do not cast pointers into more strictly aligned pointer types | |||||||||||||||||
PC-lint Plus |
| 2445 | Partially supported: reports casts directly from a pointer to a less strictly aligned type to a pointer to a more strictly aligned type | |||||||||||||||||
Polyspace Bug Finder |
| Checks for source buffer misaligned with destination buffer (rule fully covered) | ||||||||||||||||||
PRQA QA-C | ||||||||||||||||||||
Include Page | PRQA QA-C_v | PRQA QA-C_v | 3305 | Fully implemented | PRQA QA-C++ | |||||||||||||||
Include Page | cplusplus:PRQA QA-C++_V | cplusplus:PRQA QA-C++_V | 3033, 3038 | PVS-Studio |
| V548, V641, V1032 | ||||||||||||||
RuleChecker |
| pointer-cast-alignment | Fully checked |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
[Bryant 2003] | |
[ISO/IEC 9899:20112024] | 6.3.2.3, "Pointers" |
[Walfridsson 2003] | Aliasing, Pointer Casts and GCC 3.3 |
...