MISRA C:2012 Rule 9.1
The value of an object with automatic storage duration shall not be read before it has been set
描述
报告中的消息:
规则定义
The value of an object with automatic storage duration shall not be read before it has been set 1 .
理由
对于具有自动存储期的变量,将在封闭代码块的开头为其分配内存,在末尾为其解除分配内存。所有非全局变量都具有此存储期,但那些声明为 static 或 extern 的变量除外。
具有自动存储期的变量不会自动初始化,且具有不确定的值。因此,您不能在通过写入操作设置变量的值之前,读取此变量。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:初始化 |
| 类别:强制 |
| AGC 类别:强制 |
版本历史记录
在 R2014b 中推出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.