diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2011-09-24 08:01:16 (GMT) |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2011-09-24 08:01:16 (GMT) |
commit | a96b0d119d586b16f2b17fc36f49c44a5dde162d (patch) | |
tree | 66d81b2309b6a05f6a140a4c33c08f00fee9b15c | |
parent | 63c22fac727a72f0a4da8f72b12cd5f9b480376b (diff) | |
download | cpython-a96b0d119d586b16f2b17fc36f49c44a5dde162d.zip cpython-a96b0d119d586b16f2b17fc36f49c44a5dde162d.tar.gz cpython-a96b0d119d586b16f2b17fc36f49c44a5dde162d.tar.bz2 |
Backport issue #12973 itertools fix from 3.x.
-rw-r--r-- | Misc/NEWS | 6 | ||||
-rw-r--r-- | Modules/itertoolsmodule.c | 4 |
2 files changed, 6 insertions, 4 deletions
@@ -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. diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index ff25335..b51ccf9 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -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; |