MISRA C:2012 Rule 11.8
A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer
Description
Rule Definition
A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer.
Rationale
This rule forbids conversions that violate type qualification:
Casts from a pointer to a
const
object to a pointer that does not point to aconst
object. Removing theconst
qualifier allows the program to modify objects that are intended to be read-only. Attempting to access such a converted object can result in an exception.Casts from a pointer to a
volatile
object to a pointer that does not point to avolatile
object. Removing thevolatile
qualifier can allow the compiler to remove accesses to this object during optimization.Casts from a pointer to an
_Atomic
object to a pointer that does not point to a_Atomic
object. Removing the_Atomic
qualifier allows the program to circumvent the lock status of an object, resulting in memory corruption.
Such casts violate type qualification. For example, the
const
qualifier indicates the read-only status of an object.
If a cast removes the qualifier, the object is no longer read-only.
Polyspace Implementation
Polyspace® flags both implicit and explicit conversions that violate this rule.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Pointer Type Conversions |
Category: Required |
AGC Category: Required |