diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-10-19 20:20:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-19 20:20:51 (GMT) |
commit | d73205d788a32148ba9a2beaa27badbd94ab65ff (patch) | |
tree | 0d45accb52bb202f9816b91194ac3bcab0168e6a /Objects | |
parent | bbd600a17b24155f0b36f2cd473e17b09029ade6 (diff) | |
download | cpython-d73205d788a32148ba9a2beaa27badbd94ab65ff.zip cpython-d73205d788a32148ba9a2beaa27badbd94ab65ff.tar.gz cpython-d73205d788a32148ba9a2beaa27badbd94ab65ff.tar.bz2 |
bpo-38525: Fix a segmentation fault when using reverse iterators of empty dict (GH-16846)
The reverse iterator for empty dictionaries was not handling correctly shared-key dictionaries.
(cherry picked from commit 24dc2f8c56697f9ee51a4887cf0814b6600c1815)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/dictobject.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 5dad1b6..a0208be 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -3462,10 +3462,15 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype) di->di_dict = dict; di->di_used = dict->ma_used; di->len = dict->ma_used; - if ((itertype == &PyDictRevIterKey_Type || + if (itertype == &PyDictRevIterKey_Type || itertype == &PyDictRevIterItem_Type || - itertype == &PyDictRevIterValue_Type) && dict->ma_used) { + itertype == &PyDictRevIterValue_Type) { + if (dict->ma_values) { + di->di_pos = dict->ma_used - 1; + } + else { di->di_pos = dict->ma_keys->dk_nentries - 1; + } } else { di->di_pos = 0; |