mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
gh-132762: Fix underallocation bug in dict.fromkeys()(gh-133627)
The function `dict_set_fromkeys()` adds elements of a set to an existing dictionary. The size of the expanded dictionary was estimated with `PySet_GET_SIZE(iterable)`, which did not take into account the size of the existing dictionary.
This commit is contained in:
parent
2d82ab761a
commit
421ba589d0
3 changed files with 24 additions and 5 deletions
|
|
@ -3178,9 +3178,10 @@ dict_set_fromkeys(PyInterpreterState *interp, PyDictObject *mp,
|
|||
Py_ssize_t pos = 0;
|
||||
PyObject *key;
|
||||
Py_hash_t hash;
|
||||
|
||||
if (dictresize(interp, mp,
|
||||
estimate_log2_keysize(PySet_GET_SIZE(iterable)), 0)) {
|
||||
uint8_t new_size = Py_MAX(
|
||||
estimate_log2_keysize(PySet_GET_SIZE(iterable)),
|
||||
DK_LOG_SIZE(mp->ma_keys));
|
||||
if (dictresize(interp, mp, new_size, 0)) {
|
||||
Py_DECREF(mp);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue