Skip to main content

IAR Embedded Workbench for RH850 3.20.x

CERT-EXP43-C_b

In this section:
Synopsis

Avoid undefined behavior when using restrict-qualified pointers.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

The restrict qualifier requires that the pointers do not reference overlapping objects. If the objects referenced by arguments to functions overlap (meaning the objects share some common memory addresses), the behavior is undefined.

Coding standards
CERT EXP43-C

Avoid undefined behavior when using restrict-qualified pointers

Code examples

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

#include <stddef.h>
void f(size_t n, int *restrict p, const int *restrict q) {
    while (n-- > 0) {
        *p++ = *q++;
    }
}

void g(void) {
    extern int d[100];
    /* ... */
    f(50, d + 1, d); /* Undefined behavior */
}

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

#include <stddef.h>
void f(size_t n, int *restrict p, const int *restrict q) {
    while (n-- > 0) {
        *p++ = *q++;
    }
}

void g(void) {
    extern int d[100];
    extern int e[100];
    /* ... */
    f(50, d, e); /* Defined behavior  */
}