[CXX-1700] b_timestamp fields inversion Created: 05/Dec/18  Updated: 07/Dec/18  Resolved: 07/Dec/18

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

Type: Bug Priority: Major - P3
Reporter: Cristiano Toninato Assignee: Kevin Albertson
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
backported by CXX-1367 bsoncxx::types::timestamp t and i par... Closed
Duplicate
duplicates CXX-1553 Wrong ctor call to b_timestamp Closed
Related
is related to CXX-1553 Wrong ctor call to b_timestamp Closed

 Description   

Hi all.

I suspect increment and timestamp fields in struct b_timestamp are swapped.

Output of this snippet

 

       { 
              auto before = bsoncxx::types::b_timestamp();
              before.timestamp = 10;
              before.increment = 5;
              bsoncxx::builder::basic::document builder{};                                      
              builder.append(bsoncxx::builder::basic::kvp("ts", before));
              auto vv = builder.extract();
              std::cout << bsoncxx::to_json(vv) << std::endl;
              auto after = vv.view()["ts"].get_timestamp();
              std::cout << (before == after) << std::endl;
              std::cout << "t: " << after.timestamp << ", i: " << after.increment << std::endl;
        }

is

 

 

{ "ts" : { "$timestamp" : { "t" : 10, "i" : 5 } } }
0
t: 5, i: 10

I verified it happens with mongocxx 3.2.0, but it should be the same with current version of mongocxx.

 

It seems depending on get_timestamp code (return statement):

 

types::b_timestamp element::get_timestamp() const {
    BSONCXX_TYPE_CHECK(k_timestamp);
    BSONCXX_CITER;    uint32_t timestamp;
    uint32_t increment;
    bson_iter_timestamp(&iter, &timestamp, &increment);
    return types::b_timestamp{timestamp, increment};
}

because b_timestamp is defined

struct BSONCXX_API b_timestamp {
    static constexpr auto type_id = type::k_timestamp;
    uint32_t increment;
    uint32_t timestamp;
};

 

 

 

 



 Comments   
Comment by Cristiano Toninato [ 07/Dec/18 ]

Ok, thank you @Kevin Albertson, I am sorry for useless issue, I did not find CXX-1553.

Thank you, I will apply that correction on library source.

Best regards,

Cristiano

Comment by Kevin Albertson [ 06/Dec/18 ]

Hi criton, thank you for the report. This should have been fixed in 3.3.0 in CXX-1553. Please try upgrading to the latest 3.4.0 release.

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