Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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):

...

ECLAIRECLAIRcastexpr

Tool

Version

Checker

Description

Compass/ROSE

 

 

 

ECLAIRLDRA tool suite

Include Page
LDRAECLAIR_VLDRA
ECLAIR_V

203 Scastexpr

Fully implemented.

GCC

Include Page
GCC_V
GCC_V

 

Can detect violations of this recommendation when the -Wcast-qual flag is used.

Compass/ROSE

 

 

 

LDRA tool suite

Include Page
LDRA

ECLAIR

Include Page
_V
LDRA_V

203 S

Fully implemented.

PRQA QA-C
Include Page
PRQA_V
PRQA_V
0311Fully implemented.

...

CERT C++ Secure Coding StandardEXP35-CPP. Do not cast away a const qualification
ISO/IEC TR 24772Pointer casting and pointer type changes [HFC] and
Type system [IHN]
MISRA-CRule 11.5 (required): A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer
MITRE CWECWE-704, Incorrect type conversion or cast

...