Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-879

Error-prone use of std::time_t in bsoncxx::types::b_date

    XMLWordPrintable

    Details

    • Sprint:
      Platforms 13 (04/22/16)

      Description

      We're in the process of testing conversion of our code base from the legacy C++ driver to the 3.0 driver.

      In the legacy driver, it's a common use case to use the BSONObjBuilder's appendTimeT() function, which accepts a time_t.

      The closest analog to this in the 3.0 driver appears to be bsoncxx::types::b_date class, which accepts either an int64 or a std::chrono::system_clock::time_point.

      Neither of these are actually what you want when you've got a std::time_t, but it's not unreasonable for someone performing this conversion to hand the class a time_t, which will compile without issue or warning, and which results in Bad Things happening.

      It might be advantageous to at the least note in the documentation or porting notes that if one is moving from the legacy driver, then use of std::chrono::system_clock::from_time_t to get a time_point is one option here.

        Attachments

          Activity

            People

            Assignee:
            samantha.ritter Samantha Ritter
            Reporter:
            alb@neptunesystems.com Allan Bazinet
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: