C and C++


CONCURRENCY.C_ATOMIC.INIT : Inappropriate C Atomic Initialization

要旨

An atomic variable is accessed, but it has not been initialized. There are two cases:

For the sake of this check, a variable is considered to be atomic if it is declared with the _Atomic type specifier or has any atomic type defined in <stdatomic.h>.

Note: if an atomic variable is used without being initialized, CodeSonar will issue an Uninitialized Variable warning.

プロパティ

クラス名 Inappropriate C Atomic Initialization
日本語クラス名 Inappropriate C Atomic Initialization
クラス分類 信頼性 (reliability)
ニーモニック CONCURRENCY.C_ATOMIC.INIT
カテゴリー
MisraC2023 MisraC2023:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  MisraC2023:9.7 Atomic objects shall be appropriately initialized before being accessed
Misra2012 Misra2012:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  Misra2012:9.7 Atomic objects shall be appropriately initialized before being accessed
CWE CWE:665 Improper Initialization
  CWE:908 Use of Uninitialized Resource
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Inappropriate C Atomic Initialization"

#include <stdint.h>
#include <stdatomic.h>

int32_t concurrency_c_atomic_init( void ){
    _Atomic int32_t good1 = 111;                               /* ok: direct initialization */
    _Atomic int32_t good2;
    int32_t _Atomic * goodp;
    _Atomic int32_t bad1;
    _Atomic int32_t bad2;
    _Atomic int32_t bad3;
    int32_t _Atomic * badp;

    atomic_init(&good2, 222);                                 /* ok: initialization with atomic_init() */

    good1 = 555;                                              /* ok: good1 previously initialized */
    goodp = &good2;                                           /* ok: good2 previously initialized */

    bad1 = 333;                       /* 'Inappropriate C Atomic Initialization' warning issued here
                                       *  - not direct initialization and not using atomic_init()
                                       */
    badp = &bad2;                     /* 'Inappropriate C Atomic Initialization' warning issued here
                                       * - taking address of uninitialized atomic variable
                                       */
    *badp = 444;                      /* 'Inappropriate C Atomic Initialization' warning issued here
                                       * - writing through pointer into uninitialized atomic variable
                                       */

    return bad3;                               /* 'Uninitialized Variable' warning issued here
                                                * - use of ininitialized atomic variable
                                                */
}

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

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