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 | Remediation CostRepairable | Priority | Level |
|---|---|---|---|---|---|---|
EXP05-C | Medium | Probable | No | NoMedium | 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 |
| Checks for cast to pointer that removes const qualification (rec. fully supported) | PRQA QA-C | ||||||||||||
| Include Page | PRQA QA-C_v | PRQA QA-C_v | 0311, 0431 | Fully implemented | |||||||||||
| RuleChecker |
| pointer-qualifier-cast-const pointer-qualifier-cast-const-implicit | Fully checked |
...