[Python-checkins] bpo-38555: Fix an undefined behavior. (GH-16883)

Serhiy Storchaka webhook-mailer at python.org
Wed Oct 23 07:48:12 EDT 2019


https://github.com/python/cpython/commit/2e3d873d3bd0ef4708c4fa06b6cd6972574cb9af
commit: 2e3d873d3bd0ef4708c4fa06b6cd6972574cb9af
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-10-23T14:48:08+03:00
summary:

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

files:
M Objects/dictobject.c

diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 5ac7bb102b211..d909f220a984b 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;



More information about the Python-checkins mailing list