]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-105375: Improve array.array exception handling (GH-105594) (#105644)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 11 Jun 2023 10:24:22 +0000 (03:24 -0700)
committerGitHub <noreply@github.com>
Sun, 11 Jun 2023 10:24:22 +0000 (10:24 +0000)
Fix a bug where 'tp_richcompare' could end up overwriting an exception.
(cherry picked from commit 35cff545db7c7912046c0ce5627db2e4d2b60f57)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst [new file with mode: 0644]
Modules/arraymodule.c

diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst
new file mode 100644 (file)
index 0000000..21aea1b
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a bug in :class:`array.array` where an exception could end up being
+overwritten.
index f94bbec8e0bb3c131394fbf6ae861f7a899bbff0..6680820d8e61bc2219a42de9c17b70943df7ded6 100644 (file)
@@ -739,10 +739,12 @@ array_richcompare(PyObject *v, PyObject *w, int op)
     k = 1;
     for (i = 0; i < Py_SIZE(va) && i < Py_SIZE(wa); i++) {
         vi = getarrayitem(v, i);
+        if (vi == NULL) {
+            return NULL;
+        }
         wi = getarrayitem(w, i);
-        if (vi == NULL || wi == NULL) {
-            Py_XDECREF(vi);
-            Py_XDECREF(wi);
+        if (wi == NULL) {
+            Py_DECREF(vi);
             return NULL;
         }
         k = PyObject_RichCompareBool(vi, wi, Py_EQ);