Skip to content

Commit d3c69ed

Browse files
[3.12] gh-105375: Improve array.array exception handling (GH-105594) (#105644)
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 bf6e0e6 commit d3c69ed

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
@@ -739,10 +739,12 @@ array_richcompare(PyObject *v, PyObject *w, int op)
739739
k = 1;
740740
for (i = 0; i < Py_SIZE(va) && i < Py_SIZE(wa); i++) {
741741
vi = getarrayitem(v, i);
742+
if (vi == NULL) {
743+
return NULL;
744+
}
742745
wi = getarrayitem(w, i);
743-
if (vi == NULL || wi == NULL) {
744-
Py_XDECREF(vi);
745-
Py_XDECREF(wi);
746+
if (wi == NULL) {
747+
Py_DECREF(vi);
746748
return NULL;
747749
}
748750
k = PyObject_RichCompareBool(vi, wi, Py_EQ);

0 commit comments

Comments
 (0)