
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 64 in Appendix J of the C Standard.
As an illustration, the C Standard [ISO/IEC 9899:2011] .As an illustration, C provides a footnote (Section 6.7.3, para. 4):
...
Tool | Version | Checker | Description | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
|
| |||||||||||||
| 203 Scastexpr | Fully implemented. | ||||||||||||||
GCC |
|
| Can detect violations of this recommendation when the | |||||||||||||
Compass/ROSE |
|
|
| |||||||||||||
| ||||||||||||||||
Include Page |
| ECLAIR
| castexpr203 S | Fully implemented. | ||||||||||||
PRQA QA-C |
| 0311 | Fully implemented. |
...
CERT C++ Secure Coding Standard | EXP35-CPP. Do not cast away a const qualification |
---|---|
ISO/IEC TR 24772 | Pointer casting and pointer type changes [HFC] and Type system [IHN] |
MISRA-C | Rule 11.5 (required): A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer |
MITRE CWE | CWE-704, Incorrect type conversion or cast |
...