summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/pr_time_unittest.cc11
-rw-r--r--base/third_party/nspr/prtime.cc12
2 files changed, 17 insertions, 6 deletions
diff --git a/base/pr_time_unittest.cc b/base/pr_time_unittest.cc
index 416094c..6dda299 100644
--- a/base/pr_time_unittest.cc
+++ b/base/pr_time_unittest.cc
@@ -205,6 +205,17 @@ TEST_F(PRTimeTest, ParseTimeTestEpochNeg1) {
EXPECT_EQ(-1, parsed_time.ToTimeT());
}
+// If time_t is 32 bits, a date after year 2038 will overflow time_t and
+// cause timegm() to return -1. The parsed time should not be 1 second
+// before epoch.
+TEST_F(PRTimeTest, ParseTimeTestEpochNotNeg1) {
+ Time parsed_time;
+
+ EXPECT_EQ(true, Time::FromString(L"Wed Dec 31 23:59:59 GMT 2100",
+ &parsed_time));
+ EXPECT_NE(-1, parsed_time.ToTimeT());
+}
+
TEST_F(PRTimeTest, ParseTimeTestEpochNeg2) {
Time parsed_time;
diff --git a/base/third_party/nspr/prtime.cc b/base/third_party/nspr/prtime.cc
index d9392a8..c3c271b 100644
--- a/base/third_party/nspr/prtime.cc
+++ b/base/third_party/nspr/prtime.cc
@@ -158,22 +158,22 @@ PR_ImplodeTime(const PRExplodedTime *exploded)
exp_tm.tm_mon = exploded->tm_month;
exp_tm.tm_year = exploded->tm_year - 1900;
- // We assume that time_t is defined as a long.
time_t absolute_time = timegm(&exp_tm);
// If timegm returned -1. Since we don't pass it a time zone, the only
// valid case of returning -1 is 1 second before Epoch (Dec 31, 1969).
if (absolute_time == -1 &&
- exploded->tm_year != 1969 && exploded->tm_month != 11 &&
- exploded->tm_mday != 31 && exploded->tm_hour != 23 &&
- exploded->tm_min != 59 && exploded->tm_sec != 59) {
+ !(exploded->tm_year == 1969 && exploded->tm_month == 11 &&
+ exploded->tm_mday == 31 && exploded->tm_hour == 23 &&
+ exploded->tm_min == 59 && exploded->tm_sec == 59)) {
+ // If we get here, time_t must be 32 bits.
// Date was possibly too far in the future and would overflow. Return
// the most future date possible (year 2038).
if (exploded->tm_year >= 1970)
- return static_cast<PRTime>(LONG_MAX) * kSecondsToMicroseconds;
+ return INT_MAX * kSecondsToMicroseconds;
// Date was possibly too far in the past and would underflow. Return
// the most past date possible (year 1901).
- return static_cast<PRTime>(LONG_MIN) * kSecondsToMicroseconds;
+ return INT_MIN * kSecondsToMicroseconds;
}
PRTime result = static_cast<PRTime>(absolute_time);