Skip to main content

IAR Embedded Workbench for RX 5.20

CERT-EXP34-C_f

In this section:
Synopsis

Do not dereference null pointers.

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

Dereferencing a null pointer is undefined behavior. On many platforms, dereferencing a null pointer results in abnormal program termination, but this is not required by the standard. This check is identical to PTR-null-cmp-bef-fun.

Coding standards
CERT EXP34-C

Do not dereference null pointers

Code examples

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

#define NULL ((void *) 0)

int bar(int *x){
  *x = 3;
  return 0;
}

int foo(int *x) {
  if (x != NULL) {    
    *x = 4;
  }
  bar(x);
}

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

#define NULL ((void *) 0)

int bar(int *x){
  if (x != NULL)
    *x = 3;
  return 0;
}

int foo(int *x) {
  if (x != NULL) {    
    *x = 4;
  }
  bar(x);
}