mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
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.
This commit is contained in:
parent
8abc3f4f91
commit
8709490f48
3 changed files with 46 additions and 40 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue