Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2f6bc7

Browse files
committed
Issue #12973: Fix itertools bug caused by signed integer overflow. Thanks Stefan Krah.
1 parent adde86d commit b2f6bc7

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Core and Builtins
1717
- Issue #13021: Missing decref on an error path. Thanks to Suman Saha for
1818
finding the bug and providing a patch.
1919

20-
- Issue #12973: Fix overflow check that relied on undefined behaviour in
21-
list_repeat. This bug caused test_list to fail with recent versions
22-
of Clang.
20+
- Issue #12973: Fix overflow checks that relied on undefined behaviour in
21+
list_repeat (listobject.c) and islice_next (itertoolsmodule.c). These bugs
22+
caused test failures with recent versions of Clang.
2323

2424
- Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now
2525
mapped to POSIX errno ENOTDIR (previously EINVAL).

Modules/itertoolsmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,9 @@ islice_next(isliceobject *lz)
12341234
return NULL;
12351235
lz->cnt++;
12361236
oldnext = lz->next;
1237-
lz->next += lz->step;
1237+
/* The (size_t) cast below avoids the danger of undefined
1238+
behaviour from signed integer overflow. */
1239+
lz->next += (size_t)lz->step;
12381240
if (lz->next < oldnext || (stop != -1 && lz->next > stop))
12391241
lz->next = stop;
12401242
return item;

0 commit comments

Comments
 (0)