<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 22:00:39 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CXX-879] Error-prone use of std::time_t in bsoncxx::types::b_date</title>
                <link>https://jira.mongodb.org/browse/CXX-879</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;We&apos;re in the process of testing conversion of our code base from the legacy C++ driver to the 3.0 driver.&lt;/p&gt;

&lt;p&gt;In the legacy driver, it&apos;s a common use case to use the BSONObjBuilder&apos;s appendTimeT() function, which accepts a time_t.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Neither of these are actually what you want when you&apos;ve got a std::time_t, but it&apos;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;
</description>
                <environment></environment>
        <key id="275011">CXX-879</key>
            <summary>Error-prone use of std::time_t in bsoncxx::types::b_date</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="samantha.ritter@mongodb.com">Samantha Ritter</assignee>
                                    <reporter username="alb@neptunesystems.com">Allan Bazinet</reporter>
                        <labels>
                    </labels>
                <created>Fri, 25 Mar 2016 00:43:59 +0000</created>
                <updated>Mon, 8 Jan 2024 15:30:39 +0000</updated>
                            <resolved>Fri, 15 Apr 2016 17:44:59 +0000</resolved>
                                    <version>3.0.0</version>
                                    <fixVersion>3.0.2</fixVersion>
                                    <component>BSON</component>
                    <component>Documentation</component>
                    <component>Implementation</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1237378" author="xgen-internal-githook" created="Fri, 15 Apr 2016 17:44:43 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;samantharitter&apos;, u&apos;name&apos;: u&apos;samantharitter&apos;, u&apos;email&apos;: u&apos;samantha.ritter@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-879&quot; title=&quot;Error-prone use of std::time_t in bsoncxx::types::b_date&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-879&quot;&gt;&lt;del&gt;CXX-879&lt;/del&gt;&lt;/a&gt; Remove int64_t constructor for b_date&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/commit/67968af46a9dd3e7fd78866019162d9e4a9bb15a&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/commit/67968af46a9dd3e7fd78866019162d9e4a9bb15a&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1233693" author="samantha.ritter@10gen.com" created="Tue, 12 Apr 2016 18:54:18 +0000"  >&lt;p&gt;code review: &lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/pull/480&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/pull/480&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1215614" author="alb@neptunesystems.com" created="Fri, 25 Mar 2016 18:09:14 +0000"  >&lt;p&gt;That seems reasonable to me in terms of attempting to prevent errors; it&apos;s not that difficult to obtain a time_point from a variety of other representations, and it would seem that you&apos;d then be able to eliminate the &apos;no matching call to append&apos; issue that the BSON stream insertion operator now issues when passed a time_point.&lt;/p&gt;</comment>
                            <comment id="1215363" author="jason.carey" created="Fri, 25 Mar 2016 16:15:43 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alb&quot; class=&quot;user-hover&quot; rel=&quot;alb&quot;&gt;alb&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;After a little bit of discussion, we&apos;re completely in agreement that leaving the integer constructor is a little too dangerous.  I think the best way forward is to remove the int64_t constructor and only support system_clock::time_point&apos;s and chrono::milliseconds.&lt;/p&gt;

&lt;p&gt;That should make it obvious that time_t&apos;s need to be coerced to time_points via system_clock::from_time_t, and will require anyone with a random integer to tell us it&apos;s in milliseconds.  Which is about as good as the type system can do for us.&lt;/p&gt;</comment>
                            <comment id="1215181" author="acm" created="Fri, 25 Mar 2016 12:30:25 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alb&quot; class=&quot;user-hover&quot; rel=&quot;alb&quot;&gt;alb&lt;/a&gt; - Thanks for the bug report. I think the API of b_date does need some reconsideration. Our goal with the new interface is to make it difficult or impossible to do the wrong thing (unlike the old driver). The challenge here is that the BSON date time is explicitly defined to be a signed 64-bit integer, and we really do want to allow access to it in its raw form. But your point about subtle trouble when passing in a time_t is well taken. I&apos;m also somewhat suspicious that we should be naming the clock here at all.&lt;/p&gt;

&lt;p&gt;Perhaps the solution is to only permit construction of a b_date from a std::chrono::milliseconds, but we allow the result to be read as either an int64_t or as a std::chrono::milliseconds.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrdiif:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="978">Platforms 13 (04/22/16)</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>