Skip to content

Commit 35cff54

Browse files
gh-105375: Improve array.array exception handling (#105594)
Fix a bug where 'tp_richcompare' could end up overwriting an exception.
1 parent 01f4230 commit 35cff54

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
@@ -767,10 +767,12 @@ array_richcompare(PyObject *v, PyObject *w, int op)
767767
k = 1;
768768
for (i = 0; i < Py_SIZE(va) && i < Py_SIZE(wa); i++) {
769769
vi = getarrayitem(v, i);
770+
if (vi == NULL) {
771+
return NULL;
772+
}
770773
wi = getarrayitem(w, i);
771-
if (vi == NULL || wi == NULL) {
772-
Py_XDECREF(vi);
773-
Py_XDECREF(wi);
774+
if (wi == NULL) {
775+
Py_DECREF(vi);
774776
return NULL;
775777
}
776778
k = PyObject_RichCompareBool(vi, wi, Py_EQ);

0 commit comments

Comments
 (0)