Skip to content

Commit 401fff7

Browse files
authored
gh-121459: Add missing return to _PyDict_LoadGlobalStackRef (#124085)
We need to return immediately if there's an error during dictionary lookup. Also avoid the conditional-if operator. MSVC versions through v19.27 miscompile compound literals with side effects within a conditional operator. This caused crashes in the Windows10 buildbot.
1 parent 9dacf43 commit 401fff7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Objects/dictobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,12 @@ _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t h
15501550
{
15511551
PyObject *val;
15521552
Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &val);
1553-
*value_addr = val == NULL ? PyStackRef_NULL : PyStackRef_FromPyObjectNew(val);
1553+
if (val == NULL) {
1554+
*value_addr = PyStackRef_NULL;
1555+
}
1556+
else {
1557+
*value_addr = PyStackRef_FromPyObjectNew(val);
1558+
}
15541559
return ix;
15551560
}
15561561

@@ -2483,7 +2488,7 @@ _PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObje
24832488
/* namespace 1: globals */
24842489
ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res);
24852490
if (ix == DKIX_ERROR) {
2486-
*res = PyStackRef_NULL;
2491+
return;
24872492
}
24882493
if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) {
24892494
return;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy