C and C++


LANG.STRUCT.LOOP.MAE : 複数のループ中断

要旨

ループ中に複数のループ中断命令 (break 文もしくは goto 文)が存在します。

プロパティ

クラス名 Multiple Abnormal Loop Exits
日本語クラス名 複数のループ中断
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.LOOP.MAE
カテゴリー
MisraC2023 MisraC2023:15.4 There should be no more than one break or goto statement used to terminate any iteration statement
Misra2012 Misra2012:15.4 There should be no more than one break or goto statement used to terminate any iteration statement
Misra2004 Misra2004:14.6 For any iteration statement there shall be at most one break statement used for loop termination
MisraC++2008 MisraC++2008:6-6-4 For any iteration statement there shall be no more than one break or goto statement used for loop termination.
CWE CWE:1120 Excessive Code Complexity
JSF++ JSF++:191 The break statement shall not be used (except to terminate the cases of a switch statement).
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Multiple Abnormal Loop Exits"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void multiloopexit(int i){
    int x;
    for (x=0; x < 10; x++){   /* 'Multiple Abnormal Loop Exits' warning issued here. */
        if (x < i) { break;}
        /* ... */
        if (x < 2*i) {break;}
    }
}

void notmultiloopexit(int i){
    int x,y;
    for (x=0; x < 10; x++){             /* ok: this loop only has one abnormal exit. */
      if (x < i) { break;}                          /* exits from outer loop */
        /* ... */
        for (y = 0; y < 10; y++){       /* ok: this loop only has one abnormal exit. */  
            if (y < i) {break;}                     /* exits from inner loop to outer loop */
            /* ... */
        }
    }
}

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

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