MISRA C:2023 Rule 9.1
The value of an object with automatic storage duration shall not be read before it has been set
自 R2024a 起
描述
报告中的消息:
规则定义
The value of an object with automatic storage duration shall not be read before it has been set 1 .
理由
对于具有自动存储期的变量,将在封闭代码块的开头为其分配内存,在末尾为其解除分配内存。所有非全局变量都具有此存储期,但那些声明为 static
或 extern
的变量除外。
具有自动存储期的变量不会自动初始化,且具有不确定的值。因此,您不能在通过写入操作设置变量的值之前,读取此变量。
Polyspace 实现
如果您的代码包含以下问题,则 Polyspace® 会报告违反此规则:
Polyspace 会报告未初始化的 _Atomic
限定变量违反了此问题规则。您可以使用代码注释来对这些违规进行申述。请参阅为代码添加注解并隐藏已知或可接受的结果。或者,您可以使用 Polyspace 用户界面来对这些违规进行申述。请参阅通过 Bug 修复或申述在 Polyspace 用户界面中处理结果。
故障排除
如果您预计存在违规,但未看到该违规,请参阅Diagnose Why Coding Standard Violations Do Not Appear as Expected。
示例
检查信息
组:初始化 |
类别:强制 |
AGC 类别:强制 |
版本历史记录
在 R2024a 中推出
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.