Skip to content

Commit c932f72

Browse files
gh-105375: Improve _decimal error handling (#105605)
Fix a bug where an exception could end up being overwritten.
1 parent 16d4968 commit c932f72

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in :mod:`decimal` where an exception could end up being overwritten.

Modules/_decimal/_decimal.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3611,9 +3611,13 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
36113611
goto error;
36123612
}
36133613
Py_SETREF(numerator, _py_long_floor_divide(numerator, tmp));
3614+
if (numerator == NULL) {
3615+
Py_DECREF(tmp);
3616+
goto error;
3617+
}
36143618
Py_SETREF(denominator, _py_long_floor_divide(denominator, tmp));
36153619
Py_DECREF(tmp);
3616-
if (numerator == NULL || denominator == NULL) {
3620+
if (denominator == NULL) {
36173621
goto error;
36183622
}
36193623
}

0 commit comments

Comments
 (0)