Cyclomatic complexity exceeds threshold
The cyclomatic complexity of a function is greater than the defined cyclomatic complexity threshold of a function
Since R2021a
Description
Polyspace® calculates the cyclomatic complexity of a function by adding one to the number
of decision points. A decision point is a statement that causes your program to branch into
two paths. This defect is raised when the cyclomatic complexity of a function is greater than
the defined cyclomatic complexity threshold. For details about how Polyspace calculates cyclomatic complexity, see Cyclomatic Complexity
.
Polyspace uses the default threshold 10 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 Cyclomatic Complexity
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 function contains too many branches. Such functions are difficult to test and might contain unknown defects or bugs that are difficult to debug.
Fix
To fix this check:
Refactor your code to avoid nested control structures.
Refactor your code to split a complex function into multiple functions that are simpler and easy to test.
Modify the checker selection XML file to appraise the cyclomatic complexity threshold.
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:
SC17
|
Default Threshold: 10 |
Version History
Introduced in R2021a