[CXX-2140] Coverity analysis defect 105007: Uninitialized scalar field Created: 07/Dec/20  Updated: 27/Oct/23  Resolved: 21/Jul/23

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: size-small
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CXX-2632
Quarter: FY24Q2

 Description   

Uninitialized scalar field

The field will contain an arbitrary value left over from earlier computations. A scalar field is not initialized by the constructor
/data/src/c-driver-install/include/libbson-1.0/bson/bson-types.h:129: UNINIT_CTOR 105007 Class member declaration for "flags".
/src/mongocxx/private/libbson.cpp:56: UNINIT_CTOR 105007 Non-static class member field "_bson.flags" is not initialized in this constructor nor in any functions that it calls.
/data/src/c-driver-install/include/libbson-1.0/bson/bson-types.h:130: UNINIT_CTOR 105007 Class member declaration for "len".
/src/mongocxx/private/libbson.cpp:56: UNINIT_CTOR 105007 Non-static class member field "_bson.len" is not initialized in this constructor nor in any functions that it calls.



 Comments   
Comment by Kevin Albertson [ 21/Jul/23 ]

scoped_bson_t conditionally initializes the _bson_t field. scoped_bson_t tracks if _bson_t is initialized with the _is_initialized field.

The flagged constructor documents _bson_t is conditionally initialized:

//
// Constructs a new scoped_bson_t from an optional document view_or_value.
//
// The internal bson_t is initialized if the optional is populated.
//
explicit scoped_bson_t(bsoncxx::stdx::optional<bsoncxx::document::view_or_value> doc);

Closing as "Works as Designed" given this appears to be expected behavior.

Comment by Coverity Collector User [ 07/Dec/20 ]

A new defect has been detected and assigned to kevin.albertson in Coverity Connect.
http://coverity.mongodb.com/query/defects.htm?project=CXX+master&cid=105007
The defect was flagged by checker UNINIT_CTOR in
file /src/mongocxx/private/libbson.cpp
function mongocxx::v_noabi::libbson::scoped_bson_t::scoped_bson_t(core::v1::optional<bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value>>)
and this ticket was created by kevin.albertson

Generated at Wed Feb 07 22:05:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.