Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56388

Coverity analysis defect 119895: _collection not initialized in default constructor

    • Fully Compatible
    • ALL
    • Query Execution 2021-05-31

      This is the declaration of the RestoreContext class. Note that if the default constructor is selected, _collection will be permanently uninitialized garbage because it's const. The default constructor should probably be deleted instead as the intention appears to be to use one of the constructors that provides a collection pointer.

      class RestoreContext {
      public:
          enum class RestoreType {
              kExternal,  // Restore on the PlanExecutor by an external call
              kYield      // Internal restore after yield
          };
      
          RestoreContext() = default;  // <--- should be deleted
          /* implicit */ RestoreContext(const CollectionPtr* coll) : _collection(coll) {}
          /* implicit */ RestoreContext(RestoreType type, const CollectionPtr* coll)
              : _type(type), _collection(coll) {}
      
          RestoreType type() const {
              return _type;
          }
          const CollectionPtr* collection() const {
              return _collection;
          }
      
      private:
          RestoreType _type = RestoreType::kExternal;
          const CollectionPtr* _collection;
      };
      

      Uninitialized pointer field

      The pointer field will point to an arbitrary memory location, any attempt to write may cause corruption. A pointer field is not initialized in the constructor
      /src/mongo/db/query/restore_context.h:62: UNINIT_CTOR 119895 The compiler-generated constructor for this class does not initialize "_collection".

            Assignee:
            sebastien.mendez@mongodb.com Sebastien Mendez
            Reporter:
            xgen-internal-coverity Coverity Collector User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: