Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2012-Rule-11.9

In this section:
Synopsis

(Required) The macro NULL shall be the only permitted form of integer null pointer constant

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

An integer constant was found where the NULL macro should be.

Coding standards
MISRA C:2012 Rule-11.9

(Required) The macro NULL shall be the only permitted form of integer null pointer constant

Code examples

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

#include <stdlib.h>

void example(void) {
  char *a = malloc(sizeof(char) * 10);
  if (a != 0) {
    *a = 5;
  }
}

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

#include <stdlib.h>

void example(void) {
  int *a = malloc(sizeof(int) * 10);
  if (a != NULL) {
    *a = 5;
  }
}