Dead code due to goto or break statement¶
ID: cpp/dead-code-goto Kind: problem Security severity: Severity: warning Precision: high Tags: - maintainability - external/cwe/cwe-561 Query suites: - cpp-security-and-quality.qls
Code immediately following a
break statement will not be executed, unless there is a label or switch case. When the code is necessary, this leads to logical errors or resource leaks. If the code is unnecessary, it may confuse readers.
If the unreachable code is necessary, move the
break statement to after the code. Otherwise, delete the unreachable code.
goto err1; free(pointer); // BAD: this line is unreachable err1: return -1; free(pointer); // GOOD: this line is reachable goto err2; err2: return -1;
The CERT C Secure Coding Standard: MSC12-C. Detect and remove code that has no effect or is never executed.
Common Weakness Enumeration: CWE-561.