summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-10-23 11:48:08 (GMT)
committerGitHub <noreply@github.com>2019-10-23 11:48:08 (GMT)
commit2e3d873d3bd0ef4708c4fa06b6cd6972574cb9af (patch)
tree3188a8d947d5474593ef026f3f172411094f1d83
parentd34ac305327420bd68f05e201b63d2a665b073f8 (diff)
downloadcpython-2e3d873d3bd0ef4708c4fa06b6cd6972574cb9af.zip
cpython-2e3d873d3bd0ef4708c4fa06b6cd6972574cb9af.tar.gz
cpython-2e3d873d3bd0ef4708c4fa06b6cd6972574cb9af.tar.bz2
bpo-38555: Fix an undefined behavior. (GH-16883)
-rw-r--r--Objects/dictobject.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 5ac7bb1..d909f22 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -3830,22 +3830,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;