[Python-checkins] cpython: Issue #19748: On AIX, time.mktime() now raises an OverflowError for year

victor.stinner python-checkins at python.org
Fri Feb 21 09:28:11 CET 2014


http://hg.python.org/cpython/rev/502c8b7e8ad2
changeset:   89316:502c8b7e8ad2
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Feb 21 09:27:17 2014 +0100
summary:
  Issue #19748: On AIX, time.mktime() now raises an OverflowError for year
outsize range [1902; 2037].

files:
  Lib/test/test_time.py |   2 +-
  Misc/NEWS             |  10 ++++++++++
  Modules/timemodule.c  |  11 +++++++++++
  3 files changed, 22 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -228,7 +228,7 @@
         self.assertEqual(time.ctime(t), 'Sun Sep 16 01:03:52 1973')
         t = time.mktime((2000, 1, 1, 0, 0, 0, 0, 0, -1))
         self.assertEqual(time.ctime(t), 'Sat Jan  1 00:00:00 2000')
-        for year in [-100, 100, 1000, 2000, 10000]:
+        for year in [-100, 100, 1000, 2000, 2050, 10000]:
             try:
                 testval = time.mktime((year, 1, 10) + (0,)*6)
             except (ValueError, OverflowError):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,6 +2,16 @@
 Python News
 +++++++++++
 
+What's New in Python 3.4.1?
+===========================
+
+Library
+-------
+
+- Issue #19748: On AIX, time.mktime() now raises an OverflowError for year
+  outsize range [1902; 2037].
+
+
 What's New in Python 3.4.0 release candidate 2?
 ===============================================
 
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -823,7 +823,18 @@
     time_t tt;
     if (!gettmarg(tup, &buf))
         return NULL;
+#ifdef _AIX
+    /* year < 1902 or year > 2037 */
+    if (buf.tm_year < 2 || buf.tm_year > 137) {
+        /* Issue #19748: On AIX, mktime() doesn't report overflow error for
+         * timestamp < -2^31 or timestamp > 2**31-1. */
+        PyErr_SetString(PyExc_OverflowError,
+                        "mktime argument out of range");
+        return NULL;
+    }
+#else
     buf.tm_wday = -1;  /* sentinel; original value ignored */
+#endif
     tt = mktime(&buf);
     /* Return value of -1 does not necessarily mean an error, but tm_wday
      * cannot remain set to -1 if mktime succeeded. */

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list