From d5423a40849995151c48e394051366759cd72539 Mon Sep 17 00:00:00 2001 From: "wtc@chromium.org" Date: Wed, 12 Aug 2009 16:41:39 +0000 Subject: 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 --- base/third_party/nspr/prtime.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'base/third_party') 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(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(LONG_MIN) * kSecondsToMicroseconds; + return INT_MIN * kSecondsToMicroseconds; } PRTime result = static_cast(absolute_time); -- cgit v1.1