CERT-EXP43-C_d
In this section:
Synopsis
Avoid undefined behavior when using restrict-qualified pointers.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
The restrict qualifier requires that the pointers do not reference overlapping objects. If the objects referenced by arguments to functions overlap (meaning the objects share some common memory addresses), the behavior is undefined.
Coding standards
- CERT EXP43-C
Avoid undefined behavior when using restrict-qualified pointers
Code examples
The following code example fails the check and will give a warning:
void func(void) {
int *restrict p1;
int *restrict q1;
int *restrict p2 = p1; /* Undefined behavior */
int *restrict q2 = q1; /* Undefined behavior */
}
The following code example passes the check and will not give a warning about this issue:
void func(void) {
int *restrict p1;
int *restrict q1;
{ /* Added inner block */
int *restrict p2 = p1; /* Valid, well-defined behavior */
int *restrict q2 = q1; /* Valid, well-defined behavior */
}
}