Skip to content

Commit 674a50e

Browse files
authored
gh-117139: Fix an incorrect borrow in bytecodes.c (#122318)
`_PyDict_SetItem_Take2` steals both the key (i.e., `sub`) and the value.
1 parent 013a092 commit 674a50e

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Python/bytecodes.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -862,13 +862,14 @@ dummy_func(
862862
PyStackRef_CLOSE(list_st);
863863
}
864864

865-
inst(STORE_SUBSCR_DICT, (unused/1, value, dict_st, sub_st -- )) {
866-
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
865+
inst(STORE_SUBSCR_DICT, (unused/1, value, dict_st, sub -- )) {
867866
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);
868867

869868
DEOPT_IF(!PyDict_CheckExact(dict));
870869
STAT_INC(STORE_SUBSCR, hit);
871-
int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, PyStackRef_AsPyObjectSteal(value));
870+
int err = _PyDict_SetItem_Take2((PyDictObject *)dict,
871+
PyStackRef_AsPyObjectSteal(sub),
872+
PyStackRef_AsPyObjectSteal(value));
872873
PyStackRef_CLOSE(dict_st);
873874
ERROR_IF(err, error);
874875
}

Python/executor_cases.c.h

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)