Skip to main content

IAR Embedded Workbench for RH850 3.20.x

PTR-singleton-arith

In this section:
Synopsis

Pointer arithmetic is performed on a pointer that points to a single object.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Pointer arithmetic is performed on a pointer that points to a single object. If this pointer is subsequently dereferenced, it might be pointing to invalid memory, causing a runtime error.

Coding standards
CWE 119

Improper Restriction of Operations within the Bounds of a Memory Buffer

Code examples

The following code example fails the check and will give a warning:

#include <stdlib.h>

void example(void) {
  int *p = malloc(sizeof(int));
  p = p + 1;
}

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

#include <stdlib.h>

void example(void) {
  int *p = malloc(sizeof(int) * 10);
  p = p + 1;
}