Skip to content

Commit 3c08e54

Browse files
[3.11] gh-105375: Improve array.array exception handling (GH-105594) (#105643)
Fix a bug where 'tp_richcompare' could end up overwriting an exception. (cherry picked from commit 35cff54) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent aaa8a49 commit 3c08e54

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug in :class:`array.array` where an exception could end up being
2+
overwritten.

Modules/arraymodule.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,12 @@ array_richcompare(PyObject *v, PyObject *w, int op)
741741
k = 1;
742742
for (i = 0; i < Py_SIZE(va) && i < Py_SIZE(wa); i++) {
743743
vi = getarrayitem(v, i);
744+
if (vi == NULL) {
745+
return NULL;
746+
}
744747
wi = getarrayitem(w, i);
745-
if (vi == NULL || wi == NULL) {
746-
Py_XDECREF(vi);
747-
Py_XDECREF(wi);
748+
if (wi == NULL) {
749+
Py_DECREF(vi);
748750
return NULL;
749751
}
750752
k = PyObject_RichCompareBool(vi, wi, Py_EQ);

0 commit comments

Comments
 (0)