Backport issue #12973 itertools fix from 3.x.

This commit is contained in:
Mark Dickinson 2011-09-24 09:01:16 +01:00
parent 63c22fac72
commit a96b0d119d
2 changed files with 6 additions and 4 deletions

View File

@ -15,9 +15,9 @@ Core and Builtins
- Issue #12973: Fix overflow checks that invoked undefined behaviour in - Issue #12973: Fix overflow checks that invoked undefined behaviour in
int.__pow__. These overflow checks were causing int.__pow__ to produce int.__pow__. These overflow checks were causing int.__pow__ to produce
incorrect results with recent versions of Clang, as a result of the incorrect results with recent versions of Clang, as a result of the
compiler optimizing the check away. Also fix similar overflow check compiler optimizing the check away. Also fix similar overflow checks
in list_repeat (which caused test_list to fail with recent versions in list_repeat (listobject.c) and islice_next (itertoolsmodule.c). These
of Clang). bugs caused test failures with recent versions of Clang.
- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase - Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
titlecased and cased non-letter characters. titlecased and cased non-letter characters.

View File

@ -1234,7 +1234,9 @@ islice_next(isliceobject *lz)
return NULL; return NULL;
lz->cnt++; lz->cnt++;
oldnext = lz->next; 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)) if (lz->next < oldnext || (stop != -1 && lz->next > stop))
lz->next = stop; lz->next = stop;
return item; return item;