From cf1602a1dce2b5ff9d5ad8b80ecfaf41a6486e5c Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sun, 1 May 2022 17:40:41 +0100 Subject: [PATCH] Fix underflow in RawIterRange::size_hint --- src/raw/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/raw/mod.rs b/src/raw/mod.rs index 356a3a8c15..5fe0a72b31 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -1963,10 +1963,14 @@ impl Iterator for RawIterRange { #[inline] fn size_hint(&self) -> (usize, Option) { // We don't have an item count, so just guess based on the range size. - ( - 0, - Some(unsafe { offset_from(self.end, self.next_ctrl) + Group::WIDTH }), - ) + let remaining_buckets = if self.end > self.next_ctrl { + unsafe { offset_from(self.end, self.next_ctrl) } + } else { + 0 + }; + + // Add a group width to include the group we are currently processing. + (0, Some(Group::WIDTH + remaining_buckets)) } }