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.STRUCT.SW.BAD : 正しく記述されていないswitch文

要旨

switch 文が以下のいずれかの問題を含んでいます。

このクラスは下記の各クラスの上位集合となります。

プロパティ

クラス名 Malformed switch Statement
日本語クラス名 正しく記述されていないswitch文
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.SW.BAD
カテゴリー
MisraC2025 MisraC2025:16.1 All switch statements shall be well-formed
MisraC2023 MisraC2023:16.1 All switch statements shall be well-formed
Misra2012 Misra2012:16.1 All switch statements shall be well-formed
Misra2004 Misra2004:15.0 The MISRA C switch syntax shall be used
AUTOSARC++14 AUTOSARC++14:M6-4-3 A switch statement shall be a well-formed switch statement.
MisraC++2008 MisraC++2008:6-4-3 A switch statement shall be a well-formed switch statement.
MisraC++2023 MisraC++2023:9.4.2 The structure of a switch statement shall be appropriate
TS17961 TS17961:5.17-swtchdflt Use of an implied default in a switch statement
CERT-C CERT-C:DCL41-C Do not declare variables inside a switch statement before the first case label
OWASP-2025 OWASP-2025:A10 Mishandling of Exceptional Conditions
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Malformed switch Statement"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void lang_struct_sw_bad(int i){

    switch(i){                                         /* has none of the listed issues */
        default: {/*...*/ break;}
        case 1:  {/*...*/ break;}
        case 2:  {/*...*/ break;}
        }

    switch(i){                      /* 'Malformed switch Statement' warning issued here */
        case 1:  {/*...*/ break;}
        default: {/*...*/ break;}
        case 2:  {/*...*/ break;}
        } 

    switch(i){                      /* 'Malformed switch Statement' warning issued here */
        case 1:  {/*...*/ break;}
        case 2:  {/*...*/ ;}
        default: {/*...*/ break;}
    } 


    switch(i){  
        case 1:{
            case 2:                 /* 'Malformed switch Statement' warning issued here */
            /*...*/ 
            break; }
        case 3:  {/*...*/ break;}
        default: {/*...*/ break;}
    }
  
    switch(i%3){                    /* 'Malformed switch Statement' warning issued here */
        case 0 :  {/*...*/ break;}
    }

    switch(i%3){                    /* 'Malformed switch Statement' warning issued here */
                                    /* 'Empty switch Statement warning also issued */
        default :  {/*...*/ break;}
    }
}

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

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

 

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