CERT-EXP39-C_d
In this section:
Synopsis
Do not access a variable through a pointer of an incompatible type.
Enabled by default
Yes
Severity/Certainty
Medium/Low

Full description
Modifying a variable through a pointer of an incompatible type (other than unsigned char) can lead to unpredictable results. This check is identical to MISRAC2012-Rule-11.3.
Coding standards
- CERT EXP39-C
Do not access a variable through a pointer of an incompatible type
- MISRA C:2012 Rule-11.3
(Required) A cast shall not be performed between a pointer to object type and a pointer to a different object type
Code examples
The following code example fails the check and will give a warning:
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
void example(void) {
uint8_t * p1;
uint32_t * p2;
p2 = (uint32_t *)p1;
}
The following code example passes the check and will not give a warning about this issue:
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
void example(void) {
uint8_t * p1;
uint8_t * p2;
p2 = (uint8_t *)p1;
}