Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Dir-4.7_b

In this section:
Synopsis

(Required) If a function returns error information, then that error information shall be tested.

Enabled by default

No

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Returned error information should be tested.

Coding standards
CWE 252

Unchecked Return Value

MISRA C:2012 Dir-4.7

(Required) If a function returns error information, then that error information shall be tested

Code examples

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

void example(void) {
  int ec = malloc(5);
  ec = 2;
}

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

void example(void) {
  int ec = malloc(5);
  if (ec)
  {
    // ...
  }
  ec = 2;
}