[SERVER-10102] mongo::Date_t::toTimeT conversion bug. Created: 05/Jul/13  Updated: 10/Dec/14  Resolved: 16/Sep/13

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 2.4.4
Fix Version/s: None

Type: Bug Priority: Trivial - P5
Reporter: Sergey Volkov Assignee: Andy Schwerin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

unsigned long long is not best suitable to store date/time values because its may be negative.

Or cast it correctly anywhere.
file misc.h:99

return millis / 1000;

this makes unsigned division and return incorrect time_t for negative ( less than '1970-01-01' )

must be:
return static_cast<long long>( millis ) / 1000;

Thanks.



 Comments   
Comment by Andy Schwerin [ 05/Jul/13 ]

Date_t cannot currently represent times before 1970-01-01. Note that at lines 97 and 98 in mongo/bson/misc.h, the code checks that millis is legally convertible to a time_t, and throws an exception if it is not.

Generated at Thu Feb 08 03:22:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.