MISRA C:2012 Rule 17.2
Functions shall not call themselves, either directly or indirectly
Description
Note
Using Code Prover for checking coding rules is no longer supported. See Version History.
Rule Definition
Functions shall not call themselves, either directly or indirectly.
Rationale
Variables local to a function are stored in the call stack. If a function calls itself directly or indirectly several times, the available stack space can be exceeded, causing serious failure. Unless the recursion is tightly controlled, it is difficult to determine the maximum stack space required.
Polyspace Implementation
The checker reports each function that calls itself, directly, indirectly, or through a function pointer. Even if several functions are involved in one recursion cycle, each function is individually reported.
You can calculate the total number of recursion cycles using the code complexity
metric Number of Recursions
.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Function |
Category: Required |
AGC Category: Required |