MISRA C:2012 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
Description
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.1
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 |
PQL Name: std.misra_c_2012.R21_20 |
Version History
Introduced in R2017a
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.