Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb26faf

Browse files
[3.11] gh-105375: Improve _decimal error handling (GH-105605) (#105648)
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 cfa0f7c commit cb26faf

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
@@ -3658,9 +3658,13 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
36583658
goto error;
36593659
}
36603660
Py_SETREF(numerator, _py_long_floor_divide(numerator, tmp));
3661+
if (numerator == NULL) {
3662+
Py_DECREF(tmp);
3663+
goto error;
3664+
}
36613665
Py_SETREF(denominator, _py_long_floor_divide(denominator, tmp));
36623666
Py_DECREF(tmp);
3663-
if (numerator == NULL || denominator == NULL) {
3667+
if (denominator == NULL) {
36643668
goto error;
36653669
}
36663670
}

0 commit comments

Comments
 (0)