Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2008-5-0-16_b

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

mediumhigh.png
Full description

Invalid pointer arithmetic with an automatic variable that is neither an array nor a pointer was found. This check is identical to PTR-arith-var, MISRAC2004-17.1_c.

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(int x) {
  *(&x+10) = 5;
}

The following code example passes the check and will not give a warning about this issue:

void example(int *x) {
  *(x+10) = 5;
}