[Python-checkins] [3.12] gh-105375: Improve _decimal error handling (GH-105605) (#105647)

erlend-aasland webhook-mailer at python.org
Sun Jun 11 06:55:25 EDT 2023


https://github.com/python/cpython/commit/b4b5565e4779d81c943bffe22ffe0972fa398702
commit: b4b5565e4779d81c943bffe22ffe0972fa398702
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2023-06-11T10:55:18Z
summary:

[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 c932f7284977ebf813313157c52d716ba225a7ac)

Co-authored-by: Erlend E. Aasland <erlend.aasland at protonmail.com>

files:
A Misc/NEWS.d/next/Library/2023-06-09-22-52-45.gh-issue-105375.6igkhn.rst
M Modules/_decimal/_decimal.c

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 000000000000..05e78fdc9b40
--- /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 0e11c879732a..0005081f7c5e 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -3615,9 +3615,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;
         }
     }



More information about the Python-checkins mailing list