Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Dead code due to goto or break statement

ID: cpp/dead-code-gotoKind: problemSecurity severity: Severity: warningPrecision: highTags:   - maintainability   - external/cwe/cwe-561Query suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

Code immediately following agoto orbreak 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.

Recommendation

If the unreachable code is necessary, move thegoto orbreak statement to after the code. Otherwise, delete the unreachable code.

Example

gotoerr1;free(pointer);// BAD: this line is unreachableerr1:return-1;free(pointer);// GOOD: this line is reachablegotoerr2;err2:return-1;

References


[8]ページ先頭

©2009-2025 Movatter.jp