☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

if 语句作用域的范围不应有误

9.1.9 ID_if_scope
目录 › next › previous

if 语句作用域的范围不应有误。

示例:

if (condition)
    statement1; statement2;  // Non-compliant

if (condition)
    statement1;
    statement2;  // Non-compliant

例中 statement2 不在 if 语句的作用域中,但看起来又和 if 语句相关,这种问题多数是由错误的宏展开或无效的缩进造成的。

为了避免这种问题,if 语句应使用大括号括起来:

if (condition) {
    statement1; statement2;  // Compliant
}

相关

ID_if_brace

参考

CWE-483
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.