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

do-while 循环体不应为空

9.4.2 ID_do_emptyBlock
目录 › next › previous

空的 do-while 循环将功能全部压缩到了条件表达式中,各子句的职责划分不明确,可读性较差。

示例:

void foo(char* d, const char* s) {
    do {} while (*d++ = *s++);       // Non-compliant
}

示例代码将循环的条件和循环产生的副作用叠加在了一起,易使人误解。

相关

ID_while_emptyBlock

参考

CWE-1071 C++ Core Guidelines ES.85
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.