Number of goto
statements exceeds threshold
The number of goto
statements in a function is greater than the
defined threshold
Since R2021a
Description
This defect is raised on a function when the number of goto
statements
in the function is greater than the define threshold. For details about how Polyspace
calculates the number of goto
statements, see Number of Goto Statements
Polyspace® uses the default threshold zero unless you specify a threshold. To specify a
selection file where you can set the threshold, use the option Set checkers by file (-checkers-selection-file)
or Checkers activation file
(-checkers-activation-file)
.
When you import comments from previous analyses by using polyspace-comments-import
, Polyspace copies any review information on the code metric Number of Goto Statements
in the
previous result to this checker in the current result. If the current result contains the same
code metric, the review information is copied to the code metric as well.
Risk
Violation of this checker might indicate that:
The module has an overly complicated flow of execution.
The module might contain unexpected or unplanned development.
With multiple goto
statements, it is difficult to
determine the exact order of code execution in the module. This confusion might lead to bugs
or an incorrect result. The complex data flow of such code makes the module difficult to
maintain and debug.
Fix
To fix this check, either change the checker threshold or refactor your code. You can
replace most uses of the goto
statement by more straightforward control
structures. In instances where a goto
statement is necessary, document it
and justify the checker by using an annotation in the code. You might want to change the
threshold to avoid triggering this check when checking legacy codebases.
A best practice is to check the complexity of a module early in development to avoid costly post-development refactoring.
Examples
Check Information
Group: Software Complexity |
Language: C | C++ |
Acronym:
SC13
|
Default Threshold: 0 |
Version History
Introduced in R2021a