]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105375: Improve _decimal error handling (#105605)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Sun, 11 Jun 2023 10:06:06 +0000 (12:06 +0200)
committerGitHub <noreply@github.com>
Sun, 11 Jun 2023 10:06:06 +0000 (12:06 +0200)
Fix a bug where an exception could end up being overwritten.

Misc/NEWS.d/next/Library/2023-06-09-22-52-45.gh-issue-105375.6igkhn.rst [new file with mode: 0644]
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 (file)
index 0000000..05e78fd
--- /dev/null
@@ -0,0 +1 @@
+Fix bug in :mod:`decimal` where an exception could end up being overwritten.
index c8ff3896ba1a13d2bbcd5d575afc9cfbaa193a01..73df3f34829f08089682fe79744711ad4a7099f0 100644 (file)
@@ -3611,9 +3611,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;
         }
     }