-
Notifications
You must be signed in to change notification settings - Fork 318
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
Fix subtraction overflow in DuplicatesBy size_hint #552
Conversation
Thanks for this. Yes,
|
I've also changed the |
src/duplicates_impl.rs
Outdated
let max_pending = std::cmp::min(self.meta.pending, hi); | ||
let max_new = std::cmp::max(hi - self.meta.pending, 0) / 2; | ||
let max_new = hi.saturating_sub(self.meta.pending) / 2; | ||
max_pending + max_new |
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.
Hi there, one thing that bothers me is that cmp::min
and saturating_sub
actually answer the same question twice. (Namely: is hi <= self.meta.pending
?)
I think it would be clearer to do this:
if hi <= self.meta.pending {
// fewer or equally many iter-remaining elements than pending elements
// => at most, each iter-remaining element is matched
hi
} else {
// fewer pending elements than iter-remaining elements
// => at most:
// * each pending element is matched
// * the other iter-remaining elements come in pairs
self.meta.pending + (hi-self.meta.pending)/2
}
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.
updated as per your suggestion
Thank you. bors r+ |
Merged as this improves the current |
Build succeeded: |
Sample that panics with
attempt to subtract with overflow
in adebug
build: