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.SE.INIT : リスト初期化子の副作用

要旨

リスト初期化子は、1つ以上の副作用を有する。

このチェックのために:

プロパティ

クラス名 Side Effects in Initializer List
日本語クラス名 リスト初期化子の副作用
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.SE.INIT
カテゴリー
MisraC2025 MisraC2025:13.1 Initializer lists shall not contain persistent side effects
MisraC2023 MisraC2023:13.1 Initializer lists shall not contain persistent side effects
Misra2012 Misra2012:13.1 Initializer lists shall not contain persistent side effects
CERT-C CERT-C:EXP30-C Do not depend on the order of evaluation for side effects
JPL JPL:19 Do not use expressions with side effects.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Side Effects in Initializer List"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

#include <string.h>

int f(int i);
int g(int i) __attribute__((const));
int h(int i) __attribute__((pure));

int SE_INIT(int x, int y, volatile int *z, char *s){ 
    int A[2] = {x+y, x-y};                          /* no side effects */
    if (!A[1]){return 1;}
    
    int B[2] = {x++, y++};   /* 'Side Effects in Initializer List' warning issued here */
    if (!B[1]){return 1;}

    int C[2] = {y, *z};      /* 'Side Effects in Initializer List' warning issued here */
    if (!C[1]){return 1;}

    int D[2] = {1, z[1]};    /* 'Side Effects in Initializer List' warning issued here */
    if (!D[1]){return 1; }

    int E[2] = {1, f(x)};    /* 'Side Effects in Initializer List' warning issued here */
    if (!E[1]){return 1;}

    int F[2] = {1, g(x)};                           /* g() declared with  __attribute__((const)) */
    if (!F[1]){return 1;}

    int G[2] = {1, h(x)};                           /* g() declared with  __attribute__((pure)) */
    if (!G[1]){return 1;}

    int H[2] = {1, strlen(s)};                      /* strlen() matches a factory setting for SIDE_EFFECT_FREE_FUNCTIONS */

    return H[1];
    /* ... */
}

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

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

 

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