SC16 Number of return statements exceeds threshold
The number of return statements in a function is greater than the
defined threshold
Description
This defect is raised on a function when the number of return statement
in the function is greater than the defined checker threshold. For details about how Polyspace
calculates the number of return statements in a function, see Number
of Return Statements
Polyspace® uses the default threshold 1 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 Return 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
Having multiple return statements makes it difficult to determine what object a function might return. Such confusion might lead to bugs and maintenance issues that are difficult to debug.
Fix
To fix this check, use a single return statement. For instance, store the return value in an object and define it conditionally instead of returning different objects in different conditionalized return statement.
Examples
Check Information
| Group: Software Complexity |
| Language: C | C++ |
Acronym:
SC16
|
| Default Threshold: 1 |
Version History
Introduced in R2021a