summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-04-09 17:12:26 (GMT)
committerGitHub <noreply@github.com>2019-04-09 17:12:26 (GMT)
commit8709490f48fc27b3dd1a16acb33bea2299c6a575 (patch)
tree93776ed6abaae382eb6c3ea2cd369fde769e9841 /Python
parent8abc3f4f91e6b523c761c7a6fa2e3405019803a1 (diff)
downloadcpython-8709490f48fc27b3dd1a16acb33bea2299c6a575.zip
cpython-8709490f48fc27b3dd1a16acb33bea2299c6a575.tar.gz
cpython-8709490f48fc27b3dd1a16acb33bea2299c6a575.tar.bz2
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/pytime.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index 68c49a8..9ff3006 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;
}