Skip to content

Commit b4b5565

Browse files
[3.12] gh-105375: Improve _decimal error handling (GH-105605) (#105647)
Fix a bug where an exception could end up being overwritten. (cherry picked from commit c932f72) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 36ecbc3 commit b4b5565

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
@@ -3615,9 +3615,13 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
36153615
goto error;
36163616
}
36173617
Py_SETREF(numerator, _py_long_floor_divide(numerator, tmp));
3618+
if (numerator == NULL) {
3619+
Py_DECREF(tmp);
3620+
goto error;
3621+
}
36183622
Py_SETREF(denominator, _py_long_floor_divide(denominator, tmp));
36193623
Py_DECREF(tmp);
3620-
if (numerator == NULL || denominator == NULL) {
3624+
if (denominator == NULL) {
36213625
goto error;
36223626
}
36233627
}

0 commit comments

Comments
 (0)