MISRA C:2023 Rule 21.20
The pointer returned by the Standard Library functions
asctime
, ctime
, gmtime
,
localtime
, localeconv
,
getenv
, setlocale
or
strerror
shall not be used following a subsequent call to the
same function
Since R2024a
Description
Rule Definition
The pointer returned by the Standard Library functions
asctime
, ctime
,
gmtime
, localtime
,
localeconv
, getenv
,
setlocale
or strerror
shall not be
used following a subsequent call to the same function.
This rule comes from MISRA C™: 2012 Amendment 1.
Rationale
The preceding functions return a pointer to an object within the Standard Library. Implementation for this object can use a static buffer that can be modified by a second call to the same function. Therefore the value accessed through a pointer before a subsequent call to the same function can change unexpectedly.
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 |
Version History
Introduced in R2024a