-
Notifications
You must be signed in to change notification settings - Fork 13.3k
core: Fix size_hint for signed integer Range<T> iterators #24865
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
I think this bug fix should be merged to the beta branch. |
@@ -2407,6 +2407,8 @@ pub trait Step: PartialOrd { | |||
/// `start` should always be less than `end`, so the result should never | |||
/// be negative. | |||
/// | |||
/// `by` must be > 0. | |||
/// | |||
/// Returns `None` if it is not possible to calculate steps_between |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanation: "Result should never be negative" above implies this.
There was an overflow bug in .size_hint() for signed iterators, which produced an hilariously incorrect size or an overflow panic. Incorrect size is a serious bug since the iterators are marked ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when the collection tries to preallocate too much). All signed range iterators were affected. > (-1i8..127).size_hint() (18446744073709551488, Some(18446744073709551488)) Bug found using quickcheck. Fixes rust-lang#24851
Updated. I chose to split unsigned and signed. Alternative to that would be to do the cast to either |
⌛ Testing commit 95be21d with merge 7b98743... |
💔 Test failed - auto-win-32-nopt-t |
This is just some weird bors failure |
@bors: retry On Tue, Apr 28, 2015 at 2:42 AM, bluss [email protected] wrote:
|
core: Fix size_hint for signed integer `Range<T>` iterators There was an overflow bug in .size_hint() for signed iterators, which produced an hilariously incorrect size or an overflow panic. Incorrect size is a serious bug since the iterators are marked ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when the collection tries to preallocate too much). > (-1i8..127).size_hint() (18446744073709551488, Some(18446744073709551488)) Bug found using quickcheck. Fixes #24851
I'd like to nominate this for beta inclusion. (Can I do that?) |
triage: beta-nominated (just want to ensure discussion; not directly advocating.) |
not accepted for beta backport. |
core: Fix size_hint for signed integer
Range<T>
iteratorsThere was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.
Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).
Bug found using quickcheck.
Fixes #24851