Reviewers: plesner,

Description:
Guard local time posix functions from NaN value of invalid dates.

Please review this at http://codereview.chromium.org/160451

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/date-delay.js
   M     src/platform-posix.cc
   M     test/mjsunit/mjsunit.status


Index: src/date-delay.js
===================================================================
--- src/date-delay.js   (revision 2600)
+++ src/date-delay.js   (working copy)
@@ -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);
Index: src/platform-posix.cc
===================================================================
--- src/platform-posix.cc       (revision 2600)
+++ src/platform-posix.cc       (working copy)
@@ -87,15 +87,19 @@


  char* OS::LocalTimezone(double time) {
+  ASSERT(!isnan(time));
    time_t tv = static_cast<time_t>(floor(time/msPerSecond));
    struct tm* t = localtime(&tv);
+  if (NULL == t) return const_cast<char*>("");
    return const_cast<char*>(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;
  }

Index: test/mjsunit/mjsunit.status
===================================================================
--- test/mjsunit/mjsunit.status (revision 2600)
+++ test/mjsunit/mjsunit.status (working copy)
@@ -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
-~----------~----~----~----~------~----~------~--~---

Reply via email to