[3.8] bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806) (GH-18989)
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>.
(cherry picked from commit 5208b4b37953a406db0ed6a9db545c2948dde989)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 4e97337..b78fced 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1027,9 +1027,13 @@
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;
PyFPE_START_PROTECT("in math_2", return 0);
r = (*func)(x, y);