]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111789: Use PyDict_GetItemRef() in Python/codecs.c (gh-112082)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 27 Nov 2023 17:53:43 +0000 (19:53 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 17:53:43 +0000 (18:53 +0100)
Python/codecs.c

index b79bf555f2f22aaa412086373bae5b0ccd18a9e5..545bf82e00dca1d4c1c6230d4946ae19c1c80c86 100644 (file)
@@ -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);