Skip to main content

IAR Embedded Workbench for RH850 3.20.x

RED-alloc-zero-bytes

In this section:
Synopsis

Checks that an allocation does not allocate zero bytes

Enabled by default

No

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Checks that an allocation does not allocate zero bytes. Allocation functions checked: malloc/calloc/valloc/alloca/operator new[]/calloc/realloc/memalign/posix_memalign.

Coding standards

This check does not correspond to any coding standard rules.

Code examples

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

#include <stdlib.h>

void foo(void) {
  int * x = (int *) malloc(0);
}

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

#include<stdlib.h>

void foo(int n) {
  int *x = (int *) malloc(n);
}

void bar(int m) {
  int n = 4;
  int *x;
  x = (int *) malloc(m);
  x = (int *) malloc(sizeof(int));
  x = (int *) realloc(0, n);
  posix_memalign(0, 4, n + 4);
  foo(n);
}