Skip to content

Commit de60f6b

Browse files
committed
address review: handle errors
1 parent b867e0b commit de60f6b

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

Modules/mathintegermodule.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,20 @@ _isqrt_rem(PyObject *n, PyObject **rem)
468468

469469
if (a_too_large) {
470470
if (rem) {
471-
Py_SETREF(b, PyNumber_Add(b, _PyLong_GetOne()));
472-
Py_SETREF(b, PyNumber_Subtract(b, a));
473-
Py_SETREF(b, PyNumber_Subtract(b, a));
471+
PyObject *tmp = PyNumber_Add(b, _PyLong_GetOne());
472+
473+
if (tmp == NULL) {
474+
Py_DECREF(b);
475+
goto error;
476+
}
477+
Py_SETREF(b, tmp);
478+
tmp = PyNumber_Add(a, a);
479+
if (tmp == NULL) {
480+
Py_DECREF(b);
481+
goto error;
482+
}
483+
Py_SETREF(b, PyNumber_Subtract(b, tmp));
484+
Py_DECREF(tmp);
474485
}
475486
Py_SETREF(a, PyNumber_Subtract(a, _PyLong_GetOne()));
476487
}

0 commit comments

Comments
 (0)