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

Miss Skeleton (bot) webhook-mailer at python.org
Wed Oct 23 08:07:27 EDT 2019


https://github.com/python/cpython/commit/c5d3ea89ee5244714f221dcfcd3be96de2f1da8d
commit: c5d3ea89ee5244714f221dcfcd3be96de2f1da8d
branch: 3.8
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-10-23T05:07:23-07:00
summary:

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

(cherry picked from commit 2e3d873d3bd0ef4708c4fa06b6cd6972574cb9af)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
M Objects/dictobject.c

diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index a0208be9246d9..76f4fefe0979f 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -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;



More information about the Python-checkins mailing list