Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Rule-21.19_a

In this section:
Synopsis

(Mandatory) The pointers returned by the Standard Library functions localeconv, getenv, setlocale or, strerror shall only be used as if they have pointer to const-qualified type.

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

The pointer returned by localeconv, getenv, setlocale or, strerror is assigned to a non-const type.

Coding standards
MISRA C:2012 Rule-21.19

(Mandatory) The pointers returned by the Standard Library functions localeconv, getenv, setlocale or, strerror shall only be used as if the have pointer to const-qualified type

Code examples

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

#include <stdlib.h>

void example(void) {
    char *a = getenv("MY_VAR");
}

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

#include <stdlib.h>

void example(void) {
    const char *a = getenv("MY_VAR");
}