[Python-checkins] [3.12] gh-105375: Improve array.array exception handling (GH-105594) (#105644)
erlend-aasland
webhook-mailer at python.org
Sun Jun 11 06:24:29 EDT 2023
https://github.com/python/cpython/commit/d3c69ed366fb6504bb1a02f7d7226b9f788b403a
commit: d3c69ed366fb6504bb1a02f7d7226b9f788b403a
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2023-06-11T10:24:22Z
summary:
[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 35cff545db7c7912046c0ce5627db2e4d2b60f57)
Co-authored-by: Erlend E. Aasland <erlend.aasland at protonmail.com>
files:
A Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst
M Modules/arraymodule.c
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 000000000000..21aea1b0b408
--- /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 f94bbec8e0bb..6680820d8e61 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -739,10 +739,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);
More information about the Python-checkins
mailing list