MISRAC++2008-5-0-16_a
In this section:
Synopsis
(Required) A pointer operand and any pointer resulting from pointer arithmetic using that operand shall both address elements of the same array.
Enabled by default
Yes
Severity/Certainty
Medium/High

Full description
Pointer arithmetic applied to a pointer that references a stack address was found. This check is identical to PTR-arith-stack, MISRAC2004-17.1_b.
Coding standards
- CWE 120
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
- MISRA C:2004 17.1
(Required) Pointer arithmetic shall only be applied to pointers that address an array or array element.
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int i;
int *p = &i;
p++;
*p = 0;
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int i;
int *p = &i;
*p = 0;
}