diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-11 10:22:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 10:22:31 (GMT) |
commit | 3c08e54ccfff5c43ba79bbb4a95ad9effb16519a (patch) | |
tree | d07a7d7ea8d12b12b22a9961882f067f0e81af6d | |
parent | aaa8a493ecb69c3d9abeee38dc205f93aa5dea95 (diff) | |
download | cpython-3c08e54ccfff5c43ba79bbb4a95ad9effb16519a.zip cpython-3c08e54ccfff5c43ba79bbb4a95ad9effb16519a.tar.gz cpython-3c08e54ccfff5c43ba79bbb4a95ad9effb16519a.tar.bz2 |
[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 35cff545db7c7912046c0ce5627db2e4d2b60f57)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst | 2 | ||||
-rw-r--r-- | Modules/arraymodule.c | 8 |
2 files changed, 7 insertions, 3 deletions
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 index 0000000..21aea1b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst @@ -0,0 +1,2 @@ +Fix a bug in :class:`array.array` where an exception could end up being +overwritten. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index a04e6a4..312ab92 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -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); |