Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC2004-17.1_c

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 invalid pointer arithmetic with an automatic variable that is neither an array nor a pointer. This check is identical to PTR-arith-var, MISRAC++2008-5-0-16_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.

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