Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overflow in `std::iter::Skip::count` #68469

Merged
merged 1 commit into from Jan 24, 2020
Merged

Conversation

@ollie27
Copy link
Contributor

ollie27 commented Jan 22, 2020

The call to count on the inner iterator can overflow even if Skip itself would return less that usize::max_value() items.

Fixes #68139

The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items.
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 22, 2020

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@timvermeulen

This comment has been minimized.

Copy link
Contributor

timvermeulen commented Jan 23, 2020

Won't this return a wrong value whenever self.n > 0 and self.iter.nth(self.n - 1) is a Some? Say, for (0..10).skip(3).

@ollie27

This comment has been minimized.

Copy link
Contributor Author

ollie27 commented Jan 23, 2020

Won't this return a wrong value whenever self.n > 0 and self.iter.nth(self.n - 1) is a Some? Say, for (0..10).skip(3).

It looks correct to me. In that example it will call nth(2) which will return Some(2) which is the third item. At that point every item that needs to be skipped will have been skipped so count() will then return 7.

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented Jan 23, 2020

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 23, 2020

📌 Commit 9d3e844 has been approved by sfackler

@timvermeulen

This comment has been minimized.

Copy link
Contributor

timvermeulen commented Jan 24, 2020

Huh yeah, not sure what I was thinking yesterday.

tmandry added a commit to tmandry/rust that referenced this pull request Jan 24, 2020
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.

Fixes rust-lang#68139
bors added a commit that referenced this pull request Jan 24, 2020
Rollup of 8 pull requests

Successful merges:

 - #68080 (Address inconsistency in using "is" with "declared here")
 - #68424 (Suggest borrowing `Vec<NonCopy>` in for loop)
 - #68438 (Account for non-types in substs for opaque type error messages)
 - #68469 (Avoid overflow in `std::iter::Skip::count`)
 - #68473 (Enable ASan on Fuchsia)
 - #68479 (Implement `unused_parens` for block return values)
 - #68483 (Add my (@flip1995) name to .mailmap)
 - #68500 (Clear out std, not std tools)

Failed merges:

r? @ghost
tmandry added a commit to tmandry/rust that referenced this pull request Jan 24, 2020
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.

Fixes rust-lang#68139
bors added a commit that referenced this pull request Jan 24, 2020
Rollup of 7 pull requests

Successful merges:

 - #68424 (Suggest borrowing `Vec<NonCopy>` in for loop)
 - #68438 (Account for non-types in substs for opaque type error messages)
 - #68469 (Avoid overflow in `std::iter::Skip::count`)
 - #68473 (Enable ASan on Fuchsia)
 - #68479 (Implement `unused_parens` for block return values)
 - #68483 (Add my (@flip1995) name to .mailmap)
 - #68500 (Clear out std, not std tools)

Failed merges:

r? @ghost
@bors bors merged commit 9d3e844 into rust-lang:master Jan 24, 2020
4 checks passed
4 checks passed
pr Build #20200122.46 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-7) Linux x86_64-gnu-llvm-7 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
@ollie27 ollie27 deleted the ollie27:skip_count branch Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.