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
描述
规则定义
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
此规则来自 MISRA C™:2012 Amendment 1。
理由
前面的函数返回指向标准库中对象的指针。此对象的实现可以使用静态缓冲区,该缓冲区可以通过对同一函数的第二次调用进行修改。因此,在后续调用同一函数之前通过指针访问的值可能会发生意外更改。
故障排除
如果您预计存在违规,但未看到该违规,请参阅Diagnose Why Coding Standard Violations Do Not Appear as Expected。
示例
检查信息
组:标准库 |
类别:强制 |
AGC 类别:强制 |
版本历史记录
在 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.