JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.FUNCS.RECURSION : Recursion

Summary

A function is directly or indirectly recursive.

Properties

Class Name Recursion
Significance style
Mnemonic LANG.FUNCS.RECURSION
Categories
MisraC2025 MisraC2025:17.2 Functions shall not call themselves, either directly or indirectly
MisraC2023 MisraC2023:17.2 Functions shall not call themselves, either directly or indirectly
Misra2012 Misra2012:17.2 Functions shall not call themselves, either directly or indirectly
Misra2004 Misra2004:16.2 Functions shall not call themselves, either directly or indirectly
AUTOSARC++14 AUTOSARC++14:A7-5-2 Functions shall not call themselves, either directly or indirectly.
MisraC++2008 MisraC++2008:7-5-4 Functions should not call themselves, either directly or indirectly.
MisraC++2023 MisraC++2023:8.2.10 Functions shall not call themselves, either directly or indirectly
CWE CWE:674 Uncontrolled Recursion
  CWE:710 Improper Adherence to Coding Standards
JSF++ JSF++:119 Functions shall not call themselves, either directly or indirectly (i.e. recursion shall not be allowed).
POW10 POW10:1 Restrict to simple control flow constructs.
JPL JPL:4 Do not use direct or indirect recursion.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Recursion"

Examples

/* example A */
int f(int a){
    if (a < 1) return -1;
    if (a == 1) return 1;
    return a * f(a-1);          /* 'Recursion' warning issued here */
}
        
/* example B */
int g2(int y);

int g1(int x){
    if (x < 5) return 1;
    return g2(x+1);
}

int g2(int y){
    if (y > 10) return 2;
    return g1(y-2);             /* 'Recursion' warning issued here */
}

Note that the warning report for example 2 will mark both call sites as contributing to a recursion cycle; the special warning description box will be located next to the one that CodeSonar encountered first.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.