MISRA C:2023 Rule 21.19
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
Since R2024a
Description
Rule Definition
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.
This rule comes from MISRA C™: 2012 Amendment 1.
Rationale
The C99 Standard states that if the program modifies the structure pointed to by the
value returned by localeconv
, or the strings returned by
getenv
, setlocale
or strerro
,
undefined behavior occurs. Treating the pointers returned by these functions as if they were
const
-qualified allows an analysis tool to detect any attempt to modify
an object through one of the pointers. Assigning the return values of the functions to
const
-qualified pointers results in the compiler issuing a diagnostic
if an attempt is made to modify an object.
Polyspace Implementation
Polyspace® reports a violation of this rule if you assign the output of these functions
to a non-const
pointer:
localeconv
,getenv
,setlocale
,strerror
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Standard libraries |
Category: Mandatory |
AGC Category: Mandatory |