...
Assigning an unaligned value to a pointer that references a type that needs to be aligned is undefined behavior 24. An implementation may notice, for example, that tmp and header must be aligned and use an inline memcpy() that uses instructions that assume aligned data.
...
Accessing a pointer or an object that is not properly aligned can cause a program to crash or give erroneous information, or it can cause slow pointer accesses (if the architecture allows misaligned accesses).
Rule | Severity | Likelihood | Detectable | RepairableRemediation Cost | Priority | Level |
|---|---|---|---|---|---|---|
EXP36-C | Low | Probable | No | NoMedium | P4P2 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| pointer-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 | |||||||
| 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.OBJ_PTR_TO_OBJ_PTR.2012 | |||||||
| LDRA tool suite |
| 94 S, 606 S | Partially implemented | ||||||
| Parasoft C/C++test |
| CERT_C-EXP36-a | 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) | |||||||
| PVS-Studio |
| V548, V641, V1032 | |||||||
| RuleChecker |
| pointer-cast-alignment | Fully checked | ||||||
| Security Reviewer - Static Reviewer |
| C67 C68 C69 C70 | Fully implemented |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...