-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
std::iter::Skip::count currently calls count on the inner iterator but that can overflow even if the Skip itself doesn't return more that usize::max_value() items.
For example:
(0..usize::max_value()).chain(0..10).skip(usize::max_value()).count()This should return 10 but currently triggers an attempt to add with overflow (or returns 0 if overflow checks are disabled).
This is caused by
rust/src/libcore/iter/adapters/mod.rs
Lines 1817 to 1820 in 1389494
| #[inline] | |
| fn count(self) -> usize { | |
| self.iter.count().saturating_sub(self.n) | |
| } |
Metadata
Metadata
Assignees
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.