Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2012-Rule-1.5_g

In this section:
Synopsis

(Required) Obsolescent language features shall not be used. Invoking realloc with a size argument equal to zero is an obsolescent feature.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found obsolescent use of realloc with size argument zero.

Coding standards
MISRA C:2012 Rule-1.5

(Required) Obsolescent language features shall not be used.

Code examples

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

#include <stdlib.h>

void fail(void) 
{
  int *ptr = 0; 
  ptr = (int*)realloc(ptr, 0);
}

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

#include <stdlib.h>

void pass(void) 
{
  int *ptr = 0; 
  ptr = (int*)realloc(ptr, sizeof(int));
}