From 8709490f48fc27b3dd1a16acb33bea2299c6a575 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 9 Apr 2019 19:12:26 +0200 Subject: bpo-34373: Fix time.mktime() on AIX (GH-12726) Fix time.mktime() error handling on AIX for year before 1970. Other changes: * mktime(): rename variable 'buf' to 'tm'. * _PyTime_localtime(): * Use "localtime" rather than "ctime" in the error message (specific to AIX). * Always initialize errno to 0 just in case if localtime_r() doesn't set errno on error. * On AIX, avoid abs() which is limited to int type. * EINVAL constant is now always available. --- Python/pytime.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'Python/pytime.c') diff --git a/Python/pytime.c b/Python/pytime.c index 68c49a86da..9ff300699f 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -1062,26 +1062,23 @@ _PyTime_localtime(time_t t, struct tm *tm) } return 0; #else /* !MS_WINDOWS */ + #ifdef _AIX - /* AIX does not return NULL on an error - so test ranges - asif! - (1902-01-01, -2145916800.0) - (2038-01-01, 2145916800.0) */ - if (abs(t) > (time_t) 2145916800) { -#ifdef EINVAL + /* bpo-34373: AIX does not return NULL if t is too small or too large */ + if (t < -2145916800 /* 1902-01-01 */ + || t > 2145916800 /* 2038-01-01 */) { errno = EINVAL; -#endif PyErr_SetString(PyExc_OverflowError, - "ctime argument out of range"); + "localtime argument out of range"); return -1; } #endif + + errno = 0; if (localtime_r(&t, tm) == NULL) { -#ifdef EINVAL if (errno == 0) { errno = EINVAL; } -#endif PyErr_SetFromErrno(PyExc_OSError); return -1; } -- cgit v1.2.1