bpo-38555: Fix an undefined behavior. (GH-16883)

(cherry picked from commit 2e3d873d3b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Skeleton (bot) 2019-10-23 05:07:23 -07:00 committed by GitHub
parent e113b5c3e7
commit c5d3ea89ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -3840,22 +3840,21 @@ dictreviter_iternext(dictiterobject *di)
PyDictKeysObject *k = d->ma_keys;
PyObject *key, *value, *result;
if (i < 0) {
goto fail;
}
if (d->ma_values) {
if (i < 0) {
goto fail;
}
key = DK_ENTRIES(k)[i].me_key;
value = d->ma_values[i];
assert (value != NULL);
}
else {
PyDictKeyEntry *entry_ptr = &DK_ENTRIES(k)[i];
while (i >= 0 && entry_ptr->me_value == NULL) {
while (entry_ptr->me_value == NULL) {
if (--i < 0) {
goto fail;
}
entry_ptr--;
i--;
}
if (i < 0) {
goto fail;
}
key = entry_ptr->me_key;
value = entry_ptr->me_value;