
Do not cast away a const
qualification on an object of pointer type. Casting away the const
qualification allows a program to modify the object referred to by the pointer, which may result in undefined behavior. See undefined behavior 6461 in Appendix J of the C Standard.
...
Recommendation | Severity | Likelihood | Detectable | RepairableRemediation Cost | Priority | Level |
---|---|---|---|---|---|---|
EXP05-C | Medium | Probable | No | MediumNo | P8P4 | L2L3 |
Automated Detection
Tool | Version | Checker | Description | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Astrée |
| pointer-qualifier-cast-const pointer-qualifier-cast-const-implicit | Fully checked | |||||||||||||
Axivion Bauhaus Suite |
| CertC-EXP05 | Fully implemented | |||||||||||||
CodeSonar |
| LANG.CAST.PC.CRCQ | Cast removes const qualifier | |||||||||||||
Compass/ROSE | ||||||||||||||||
| CC2.EXP05 | Fully implemented | ||||||||||||||
GCC |
| Can detect violations of this recommendation when the | ||||||||||||||
Helix QAC |
| C0311, C0431 | ||||||||||||||
LDRA tool suite |
| 203 S | Fully implemented | |||||||||||||
Parasoft C/C++test |
| CERT_C-EXP05-a | A cast shall not remove any 'const' or 'volatile' qualification from the type of a pointer or reference | |||||||||||||
PC-lint Plus |
| 9005 | Partially supported | |||||||||||||
Polyspace Bug Finder |
| Qualifier removed in conversion MISRA CERT C: 2012 Rule 11.8 | Variable qualifier is lost during conversion A cast shall not remove any const or volatile qualification from the type pointed to by a pointer | PRQA QA-C | ||||||||||||
Include Page | PRQA QA-C_v | PRQA QA-C_v | 0311, 0431 | Checks for cast to pointer that removes const qualification (rec. fully supported) Fully implemented | ||||||||||||
RuleChecker |
| pointer-qualifier-cast-const pointer-qualifier-cast-const-implicit | Fully checked |
...