Skip to main content

IAR Embedded Workbench for RL78 5.20

PTR-unchk-param

In this section:
Synopsis

A pointer parameter is not compared to NULL

Enabled by default

No

Severity/Certainty

Low/High

lowhigh.png
Full description

A function dereferences a pointer argument, without first checking that it isn't equal to NULL. Dereferencing a NULL pointer will cause an application crash.

Coding standards
CWE 822

Untrusted Pointer Dereference

Code examples

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

int deref(int *p)
{
  return *p;
}

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

#define NULL 0

int safe_deref(int *p)
{
  if (p == NULL) {
    return 0;
  } else {
    return *p;
  }
}