]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport issue #12973 itertools fix from 3.x.
authorMark Dickinson <mdickinson@enthought.com>
Sat, 24 Sep 2011 08:01:16 +0000 (09:01 +0100)
committerMark Dickinson <mdickinson@enthought.com>
Sat, 24 Sep 2011 08:01:16 +0000 (09:01 +0100)
Misc/NEWS
Modules/itertoolsmodule.c

index b4dd2159c8fd91419590c412637736b3a3da5447..c4f0cb09fe6a03e07a617e7796a5e963ae800e7e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,9 +15,9 @@ Core and Builtins
 - Issue #12973: Fix overflow checks that invoked undefined behaviour in
   int.__pow__.  These overflow checks were causing int.__pow__ to produce
   incorrect results with recent versions of Clang, as a result of the
-  compiler optimizing the check away.  Also fix similar overflow check
-  in list_repeat (which caused test_list to fail with recent versions
-  of Clang).
+  compiler optimizing the check away.  Also fix similar overflow checks
+  in list_repeat (listobject.c) and islice_next (itertoolsmodule.c).  These
+  bugs caused test failures with recent versions of Clang.
 
 - Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
   titlecased and cased non-letter characters.
index ff25335c04bc320023040dc38ba59abd9d483208..b51ccf96436c315b8c376cb7db78ac39536cc2a6 100644 (file)
@@ -1234,7 +1234,9 @@ islice_next(isliceobject *lz)
         return NULL;
     lz->cnt++;
     oldnext = lz->next;
-    lz->next += lz->step;
+    /* The (size_t) cast below avoids the danger of undefined
+       behaviour from signed integer overflow. */
+    lz->next += (size_t)lz->step;
     if (lz->next < oldnext || (stop != -1 && lz->next > stop))
         lz->next = stop;
     return item;