diff options
| author | Oliver Middleton <olliemail27@gmail.com> | 2020-01-22 20:28:28 +0000 |
|---|---|---|
| committer | Oliver Middleton <olliemail27@gmail.com> | 2020-01-22 20:28:28 +0000 |
| commit | 9d3e84432dae2e96a5e0f97be18ee09b5a2217b1 (patch) | |
| tree | d6e8e6fb3fc52907cdb2264f3cda74cabd359d51 /src/test | |
| parent | 900811e43047fc5593f39b0363373530b02c87e0 (diff) | |
| download | rust-9d3e84432dae2e96a5e0f97be18ee09b5a2217b1.tar.gz rust-9d3e84432dae2e96a5e0f97be18ee09b5a2217b1.zip | |
Avoid overflow in `std::iter::Skip::count`
The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/iterators/skip-count-overflow.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/test/ui/iterators/skip-count-overflow.rs b/src/test/ui/iterators/skip-count-overflow.rs new file mode 100644 index 00000000000..d8efc948664 --- /dev/null +++ b/src/test/ui/iterators/skip-count-overflow.rs @@ -0,0 +1,8 @@ +// run-pass +// only-32bit too impatient for 2⁶⁴ items +// compile-flags: -C overflow-checks -C opt-level=3 + +fn main() { + let i = (0..usize::max_value()).chain(0..10).skip(usize::max_value()); + assert_eq!(i.count(), 10); +} |
