Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2004-17.1_b

In this section:
Synopsis

(Required) Pointer arithmetic shall only be applied to pointers that address an array or array element.

Enabled by default

Yes

Severity/Certainty

Medium/High

mediumhigh.png
Full description

Detected pointer arithmetic applied to a pointer that references a stack address. This check is identical to PTR-arith-stack, MISRAC++2008-5-0-16_a.

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.

MISRA C++ 2008 5-0-16

(Required) A pointer operand and any pointer resulting from pointer arithmetic using that operand shall both address elements of the same array.

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;
}