diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 16:41:39 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 16:41:39 +0000 |
commit | d5423a40849995151c48e394051366759cd72539 (patch) | |
tree | 55e807fedc78f048834ce3d182ba4568c8e74fc7 /base/pr_time_unittest.cc | |
parent | 0f7bc44780e2c7894efd198ef2ac2596c0e7a058 (diff) | |
download | chromium_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/pr_time_unittest.cc')
-rw-r--r-- | base/pr_time_unittest.cc | 11 |
1 files changed, 11 insertions, 0 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; |