Backport issue #12973 itertools fix from 3.x.
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 @@
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;