bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806)

In math_2(), the first PyFloat_AsDouble() call should be checked
for failure before the second call.

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
Zackery Spytz 2020-03-14 04:45:32 -06:00 committed by GitHub
parent 3a8c56295d
commit 5208b4b379
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View file

@ -1106,9 +1106,13 @@ math_2(PyObject *const *args, Py_ssize_t nargs,
if (!_PyArg_CheckPositional(funcname, nargs, 2, 2))
return NULL;
x = PyFloat_AsDouble(args[0]);
y = PyFloat_AsDouble(args[1]);
if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
if (x == -1.0 && PyErr_Occurred()) {
return NULL;
}
y = PyFloat_AsDouble(args[1]);
if (y == -1.0 && PyErr_Occurred()) {
return NULL;
}
errno = 0;
r = (*func)(x, y);
if (Py_IS_NAN(r)) {