The cyclomatic complexity of a function is greater than the defined cyclomatic complexity threshold of a function
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 .
Polyspace uses the default threshold 10 unless you specify a threshold. To specify a
selection file where you can set the threshold, use Set checkers by file
(-checkers-selection-file) (Polyspace Bug Finder Server). Also see Reduce Software Complexity by Using Polyspace Checkers (Polyspace Bug Finder Server).
When you import comments from previous analyses by using , Polyspace copies any review information on the code metric 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.
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.
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 raise the cyclomatic complexity threshold.
A best practice is to check the complexity of a module early in development to avoid costly post-development refactoring.
| Group: Software Complexity |
| Language: C | C++ |
Acronym:
SC17
|
| Default Threshold: 10 |