C and C++


LANG.FUNCS.RECURSION : 再帰

要旨

関数が直接もしくは間接的に再帰呼び出しされています。

プロパティ

クラス名 Recursion
日本語クラス名 再帰
クラス分類 スタイル (style)
ニーモニック LANG.FUNCS.RECURSION
カテゴリー
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.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Recursion"

/* 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 */
}

注:例2のワーニングレポートでは、両方の呼び出し元が再帰サイクルの原因となります。 warning description box は CodeSonar が最初に遭遇した呼び出し箇所に表示されます。

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。