Number of recursions exceeds threshold
Number of call graph cycles over one or more functions is greater than the defined threshold
Since R2024a
Description
A recursion occurs when a function calls itself directly or indirectly. Polyspace® reports a violation of this rule when the number of such recursions exceed a
specified threshold. For details about how Polyspace calculates the number of recursions, see Number of Recursions
.
Polyspace uses the default threshold 0, following recommendation from the Hersteller
Initiative Software (HIS) standard. 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 Recursions
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
Recursion can lead to issues that are difficult to diagnose such as stack overflow. Recursive code is difficult to read and maintain, which could lead to miscalculating the amount of stack required to avoid stack overflow.
Indirect recursions that happen inadvertently are difficult to detect and could lead to stack overflow that is difficult to fix.
Fix
To fix this check, refactor your code to avoid recursion. In many cases, recursive algorithms can be replaced by loops.
Examples
Check Information
Group: Software Complexity |
Language: C | C++ |
Acronym:
SC20
|
Default Threshold: 0 |
Version History
Introduced in R2024a