Revision: 2601
Author: [email protected]
Date: Fri Jul 31 06:17:59 2009
Log: Guard local time posix functions from NaN value of invalid dates.
Review URL: http://codereview.chromium.org/160451
http://code.google.com/p/v8/source/detail?r=2601
Modified:
/branches/bleeding_edge/src/date-delay.js
/branches/bleeding_edge/src/platform-nullos.cc
/branches/bleeding_edge/src/platform-posix.cc
/branches/bleeding_edge/src/platform-win32.cc
/branches/bleeding_edge/src/platform.h
/branches/bleeding_edge/test/mjsunit/mjsunit.status
=======================================
--- /branches/bleeding_edge/src/date-delay.js Tue Jul 7 04:57:09 2009
+++ /branches/bleeding_edge/src/date-delay.js Fri Jul 31 06:17:59 2009
@@ -156,6 +156,8 @@
// NOTE: The implementation relies on the fact that no time zones have
// more than one daylight savings offset change per month.
+// This function must never be called with the argument NaN.
+// All uses of it are guarded so this does not happen.
function DaylightSavingsOffset(t) {
// Load the cache object from the builtins object.
var cache = DST_offset_cache;
@@ -219,6 +221,7 @@
var timezone_cache_timezone;
function LocalTimezone(t) {
+ if (NUMBER_IS_NAN(t)) return "";
if (t == timezone_cache_time) {
return timezone_cache_timezone;
}
@@ -464,9 +467,11 @@
value = cache.time;
} else {
value = DateParse(year);
- cache.time = value;
- cache.year = YearFromTime(LocalTimeNoCheck(value));
- cache.string = year;
+ if (!NUMBER_IS_NAN(value)) {
+ cache.time = value;
+ cache.year = YearFromTime(LocalTimeNoCheck(value));
+ cache.string = year;
+ }
}
} else {
@@ -647,6 +652,7 @@
function LocalTimezoneString(time) {
+ // time is not NaN because of checks in calling functions.
var timezoneOffset = (local_time_offset + DaylightSavingsOffset(time)) /
msPerMinute;
var sign = (timezoneOffset >= 0) ? 1 : -1;
var hours = FLOOR((sign * timezoneOffset)/60);
=======================================
--- /branches/bleeding_edge/src/platform-nullos.cc Mon May 25 03:05:56 2009
+++ /branches/bleeding_edge/src/platform-nullos.cc Fri Jul 31 06:17:59 2009
@@ -80,7 +80,7 @@
// Returns a string identifying the current timezone taking into
// account daylight saving.
-char* OS::LocalTimezone(double time) {
+const char* OS::LocalTimezone(double time) {
UNIMPLEMENTED();
return "<none>";
}
=======================================
--- /branches/bleeding_edge/src/platform-posix.cc Mon Jul 13 14:22:50 2009
+++ /branches/bleeding_edge/src/platform-posix.cc Fri Jul 31 06:17:59 2009
@@ -86,16 +86,20 @@
}
-char* OS::LocalTimezone(double time) {
+const char* OS::LocalTimezone(double time) {
+ ASSERT(!isnan(time));
time_t tv = static_cast<time_t>(floor(time/msPerSecond));
struct tm* t = localtime(&tv);
- return const_cast<char*>(t->tm_zone);
+ if (NULL == t) return "";
+ return t->tm_zone;
}
double OS::DaylightSavingsOffset(double time) {
+ ASSERT(!isnan(time));
time_t tv = static_cast<time_t>(floor(time/msPerSecond));
struct tm* t = localtime(&tv);
+ if (NULL == t) return nan_value();
return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
}
=======================================
--- /branches/bleeding_edge/src/platform-win32.cc Wed Jul 1 01:46:59 2009
+++ /branches/bleeding_edge/src/platform-win32.cc Fri Jul 31 06:17:59 2009
@@ -603,7 +603,7 @@
// Returns a string identifying the current timezone taking into
// account daylight saving.
-char* OS::LocalTimezone(double time) {
+const char* OS::LocalTimezone(double time) {
return Time(time).LocalTimezone();
}
=======================================
--- /branches/bleeding_edge/src/platform.h Wed Jul 1 01:46:59 2009
+++ /branches/bleeding_edge/src/platform.h Fri Jul 31 06:17:59 2009
@@ -143,7 +143,7 @@
// Returns a string identifying the current time zone. The
// timestamp is used for determining if DST is in effect.
- static char* LocalTimezone(double time);
+ static const char* LocalTimezone(double time);
// Returns the local time offset in milliseconds east of UTC without
// taking daylight savings time into account.
=======================================
--- /branches/bleeding_edge/test/mjsunit/mjsunit.status Fri Jul 31 01:04:41
2009
+++ /branches/bleeding_edge/test/mjsunit/mjsunit.status Fri Jul 31 06:17:59
2009
@@ -101,6 +101,5 @@
debug-handle: CRASH || FAIL
debug-clearbreakpointgroup: CRASH || FAIL
regress/regress-269: CRASH || FAIL
-regress/regress-1200351: CRASH || FAIL
regress/regress-998565: CRASH || FAIL
tools/tickprocessor: PASS || CRASH || FAIL
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---