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

注意 do-while(0) 中可疑的 continue 语句

9.4.4 ID_do_suspiciousContinue
目录 › next › previous

continue 语句和 break 语句在语义上是不同的,但在 do-while(0) 中的功效是一样的。

在 do-while(0) 的循环体中如果既有 break 语句又有 continue 语句,continue 语句被误用的可能性较大。

示例:

int foo() {
    do {
        ....
        if (cond1) {
            break;
        }
        ....
        if (cond2) {
            continue;   // Rather suspicious
        }
        ....
    } while (0);
}

建议在 do-while(0) 中只使用 break 语句,不使用 continue 语句。

参考

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