summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 16:41:39 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 16:41:39 +0000
commitd5423a40849995151c48e394051366759cd72539 (patch)
tree55e807fedc78f048834ce3d182ba4568c8e74fc7 /base
parent0f7bc44780e2c7894efd198ef2ac2596c0e7a058 (diff)
downloadchromium_src-d5423a40849995151c48e394051366759cd72539.zip
chromium_src-d5423a40849995151c48e394051366759cd72539.tar.gz
chromium_src-d5423a40849995151c48e394051366759cd72539.tar.bz2
Fix PR_ImplodeTime for Linux x64.
This fixes the following error when building for x64 targets: base/third_party/nspr/prtime.cc: In function 'PRTime PR_ImplodeTime(const PRExplodedTime*)': base/third_party/nspr/prtime.cc:173: error: integer overflow in expression base/third_party/nspr/prtime.cc:176: error: integer overflow in expression PRTime is long long (8 bytes) on ia32, and long (8 bytes) on x64. On ia32, LONG_MAX (4 bytes) converted to microseconds fits in the PRTime type, but on x64 LONG_MAX is 8 bytes and so overflows the PRTime type on conversion. Avoid these issues by only returning INT_MAX. On ia32 this is the correct value, and does not change behaviour. On x64 the call to timegm() will always succeed due to the increased range of time_t, so the error condition of -1 should never be reached. Fix a bug in the conditional expression for 1 second before epoch. Patch by Joel Stanley Original review URL: http://codereview.chromium.org/160511 R=dean,wtc BUG=18231 TEST=new unit test Review URL: http://codereview.chromium.org/164366 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-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);