summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-11-27 17:53:43 (GMT)
committerGitHub <noreply@github.com>2023-11-27 17:53:43 (GMT)
commitaa438bdd6deed225d30d87dc3a77602ffc924213 (patch)
tree4d5a8a5d3df5863599a55a8853521a2a841de3f2
parent395fd9c1808fa0babc96540744d2c915178a452b (diff)
downloadcpython-aa438bdd6deed225d30d87dc3a77602ffc924213.zip
cpython-aa438bdd6deed225d30d87dc3a77602ffc924213.tar.gz
cpython-aa438bdd6deed225d30d87dc3a77602ffc924213.tar.bz2
gh-111789: Use PyDict_GetItemRef() in Python/codecs.c (gh-112082)
-rw-r--r--Python/codecs.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index b79bf55..545bf82 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -146,15 +146,14 @@ PyObject *_PyCodec_Lookup(const char *encoding)
PyUnicode_InternInPlace(&v);
/* First, try to lookup the name in the registry dictionary */
- PyObject *result = PyDict_GetItemWithError(interp->codec_search_cache, v);
+ PyObject *result;
+ if (PyDict_GetItemRef(interp->codec_search_cache, v, &result) < 0) {
+ goto onError;
+ }
if (result != NULL) {
- Py_INCREF(result);
Py_DECREF(v);
return result;
}
- else if (PyErr_Occurred()) {
- goto onError;
- }
/* Next, scan the search functions in order of registration */
const Py_ssize_t len = PyList_Size(interp->codec_search_path);