DevNullKVEngine constructor leaves member _cachePressureForTest uninitialized

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Trivial - P5
    • 9.0.0-rc1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Storage Engines - Server Integration
    • Fully Compatible
    • ALL
    • Hide
      • Build the server with static analysis (Svace) enabled.
      • Observe the UNINIT.CTOR warning on the DevNullKVEngine default constructor: _cachePressureForTest is not initialized.
      • Inspect devnull_kv_engine.h — the member has no default initializer; inspect DevNullKVEngine::DevNullKVEngine() in devnull_kv_engine.cpp — it does not assign the member.
      Show
      Build the server with static analysis (Svace) enabled. Observe the UNINIT.CTOR warning on the DevNullKVEngine default constructor: _cachePressureForTest is not initialized. Inspect devnull_kv_engine.h — the member has no default initializer; inspect DevNullKVEngine::DevNullKVEngine() in devnull_kv_engine.cpp — it does not assign the member.
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      In src/mongo/db/storage/devnull/devnull_kv_engine.h, the member int _cachePressureForTest; is declared without a default member initializer. The DevNullKVEngine::DevNullKVEngine() constructor (in devnull_kv_engine.cpp) initializes only _engineDbPath and does not assign _cachePressureForTest, so the member is left with an indeterminate value after construction.

      The adjacent members are initialized deliberately, which indicates these fields are meant to hold defined values. Reading _cachePressureForTest before it is assigned would be undefined behavior. In the current tree the member is not read anywhere, so the defect is latent rather than active; the _forTest suffix suggests it is intended to be consumed by tests, at which point the uninitialized read would become reachable.

      Found by static analysis (Svace, UNINIT.CTOR): "Constructor may not initialize class members of 'mongo::DevNullKVEngine'. Following members aren't initialized: _cachePressureForTest."

      Suggested fix: give the member a default initializer in the header (e.g. int _cachePressureForTest = 0;) or initialize it in the constructor.

            Assignee:
            Benjamin Ulmer
            Reporter:
            Павел N/A (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: