CodeQL documentation

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

Click to see the query in the CodeQL repository

Code immediately following a goto or 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.

Recommendation

If the unreachable code is necessary, move the goto or break statement to after the code. Otherwise, delete the unreachable code.

Example

goto err1;
free(pointer); // BAD: this line is unreachable
err1: return -1;

free(pointer); // GOOD: this line is reachable
goto err2;
err2: return -1;

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy