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

Fix overflow in duplicates size hint #571

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/duplicates_impl.rs
Expand Up @@ -2,8 +2,8 @@ use std::hash::Hash;

mod private {
use std::collections::HashMap;
use std::hash::Hash;
use std::fmt;
use std::hash::Hash;

#[derive(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
Expand Down Expand Up @@ -89,7 +89,7 @@ mod private {
// far), plus (hi - pending) / 2 pairs of never seen before items.
let hi = hi.map(|hi| {
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
});
// The lower bound is always 0 since we might only get unique items from now on
Expand Down Expand Up @@ -203,4 +203,3 @@ where
{
Duplicates::new(iter, private::ById)
}