diff options
| author | Mark Dickinson <mdickinson@enthought.com> | 2011-09-24 08:56:09 +0100 |
|---|---|---|
| committer | Mark Dickinson <mdickinson@enthought.com> | 2011-09-24 08:56:09 +0100 |
| commit | b2f6bc72a269a0c4ed389ad232b47e2a42b8dde0 (patch) | |
| tree | b1e691ab2afcc804385f38036708f598377a0051 /Modules | |
| parent | adde86d0e31ce486e72a9d1a2a7625e5e34d97e9 (diff) | |
| download | cpython-git-b2f6bc72a269a0c4ed389ad232b47e2a42b8dde0.tar.gz | |
Issue #12973: Fix itertools bug caused by signed integer overflow. Thanks Stefan Krah.
Diffstat (limited to 'Modules')
| -rw-r--r-- | Modules/itertoolsmodule.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 71d5bb646c..8b6fa855a8 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; |
