[Python-checkins] cpython (2.7): Backport issue #12973 itertools fix from 3.x.

mark.dickinson python-checkins at python.org
Sat Sep 24 10:02:35 CEST 2011


http://hg.python.org/cpython/rev/5a1cb8506cea
changeset:   72461:5a1cb8506cea
branch:      2.7
parent:      72456:0f5b64630fda
user:        Mark Dickinson <mdickinson at enthought.com>
date:        Sat Sep 24 09:01:16 2011 +0100
summary:
  Backport issue #12973 itertools fix from 3.x.

files:
  Misc/NEWS                 |  6 +++---
  Modules/itertoolsmodule.c |  4 +++-
  2 files changed, 6 insertions(+), 4 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,9 +15,9 @@
 - 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.
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1234,7 +1234,9 @@
         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;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list