]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105375: Improve array.array exception handling (#105594)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Sun, 11 Jun 2023 09:58:08 +0000 (11:58 +0200)
committerGitHub <noreply@github.com>
Sun, 11 Jun 2023 09:58:08 +0000 (11:58 +0200)
Fix a bug where 'tp_richcompare' could end up overwriting an exception.

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 1a5993819b2e13dc6a42974fd15586f0eff1bc8b..8132689c66c0af29e0b8360af0ba8abdcb3c4a89 100644 (file)
@@ -767,10 +767,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);