Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Rule-22.9

In this section:
Synopsis

(Required) The value of errno shall be tested against zero after calling an errno-setting-function.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

errno is not tested against zero after a call to an errno-setting-function.

Coding standards
MISRA C:2012 Rule-22.9

(Required) The value of errno shall be tested against zero after calling an errno-setting-function

Code examples

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

#include <errno.h>
#include <stdlib.h>
void foo(void);

void example(void) {
    char *p;
    strtol("0xDEADBEEF", &p, 16);
    foo();
    if (errno != 0) {

    }
}

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

#include <errno.h>
#include <stdlib.h>
void foo(void);

void example(void) {
    char *p;
    strtol("0xDEADBEEF", &p, 16);
    if (errno != 0) {

    }
}