Skip to content

Commit

Permalink
Always initialize res in _PyDict_LoadGlobalStackRef
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Sep 14, 2024
1 parent 67bc9cc commit 6c61fc8
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2471,13 +2471,29 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key)
void
_PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObject *key, _PyStackRef *res)
{
PyObject *obj = _PyDict_LoadGlobal(globals, builtins, key);
if (obj == NULL) {
Py_ssize_t ix;
Py_hash_t hash;

*res = PyStackRef_NULL;

hash = _PyObject_HashFast(key);
if (hash == -1) {
*res = PyStackRef_NULL;
return;
}
else {
*res = PyStackRef_FromPyObjectSteal(obj);

/* namespace 1: globals */
ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res);
if (ix == DKIX_ERROR) {
*res = PyStackRef_NULL;
}
if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) {
return;
}

/* namespace 2: builtins */
ix = _Py_dict_lookup_threadsafe_stackref(builtins, key, hash, res);
assert(ix >= 0 || PyStackRef_IsNull(*res));
}

/* Consumes references to key and value */
Expand Down

0 comments on commit 6c61fc8

Please sign in to comment.