[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 35cff545db)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Miss Islington (bot) 2023-06-11 03:22:31 -07:00 committed by GitHub
parent aaa8a493ec
commit 3c08e54ccf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -741,10 +741,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);