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++


CONCURRENCY.C_ATOMIC.INIT : Inappropriate C Atomic Initialization

Summary

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.

Properties

Class Name Inappropriate C Atomic Initialization
Significance reliability
Mnemonic CONCURRENCY.C_ATOMIC.INIT
Categories
MisraC2025 MisraC2025:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  MisraC2025:9.7 Atomic objects shall be appropriately initialized before being accessed
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
MisraC++2023 MisraC++2023:0.3.2 A function call shall not violate the function's preconditions
CWE CWE:665 Improper Initialization
  CWE:908 Use of Uninitialized Resource
CERT-C CERT-C:CON33-C Avoid race conditions when using library functions
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Inappropriate C Atomic Initialization"

Example

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

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

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