diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-11 10:58:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 10:58:56 (GMT) |
commit | cb26fafdcc2814c7ac5c080d330970c7971fff3e (patch) | |
tree | 241383b740557eceaeb0f9bdeb13da484c4443e8 | |
parent | cfa0f7c59baed2a001463ffa1fcb634677a8000c (diff) | |
download | cpython-cb26fafdcc2814c7ac5c080d330970c7971fff3e.zip cpython-cb26fafdcc2814c7ac5c080d330970c7971fff3e.tar.gz cpython-cb26fafdcc2814c7ac5c080d330970c7971fff3e.tar.bz2 |
[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 c932f7284977ebf813313157c52d716ba225a7ac)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-06-09-22-52-45.gh-issue-105375.6igkhn.rst | 1 | ||||
-rw-r--r-- | Modules/_decimal/_decimal.c | 6 |
2 files changed, 6 insertions, 1 deletions
diff --git a/Misc/NEWS.d/next/Library/2023-06-09-22-52-45.gh-issue-105375.6igkhn.rst b/Misc/NEWS.d/next/Library/2023-06-09-22-52-45.gh-issue-105375.6igkhn.rst new file mode 100644 index 0000000..05e78fd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-06-09-22-52-45.gh-issue-105375.6igkhn.rst @@ -0,0 +1 @@ +Fix bug in :mod:`decimal` where an exception could end up being overwritten. diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 6588596..0e7d379 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3658,9 +3658,13 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED) goto error; } Py_SETREF(numerator, _py_long_floor_divide(numerator, tmp)); + if (numerator == NULL) { + Py_DECREF(tmp); + goto error; + } Py_SETREF(denominator, _py_long_floor_divide(denominator, tmp)); Py_DECREF(tmp); - if (numerator == NULL || denominator == NULL) { + if (denominator == NULL) { goto error; } } |