Use of goto statement
ID |
c.maintainability.avoid_goto |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Control Flow |
Language |
C / C++ |
Description
Use of goto makes control flow harder to follow and maintain. Prefer structured control flow (loops, helper functions, early returns). Where goto is used for centralized error cleanup, consider whether a small cleanup helper © or RAII (C++) reads more clearly.
Rationale
Use of goto makes control flow harder to follow and maintain. Prefer structured control flow (loops, helper functions, early returns). Where goto is used for centralized error cleanup, consider whether a small cleanup helper © or RAII (C++) reads more clearly.
The following code illustrates the pattern detected by this rule:
int result = 0;
if (n < 0) {
// FLAGGED: Use of goto statement
goto done;
}