Skip to content

Commit 1fa1dcc

Browse files
committed
Fix index calculation in panic guard of clone_from_impl
Previously, it was possible for an uninitialized element to be dropped if all of the following occurred: - `clone_from` was called where `T: !Copy`. - The `clone` implementation of `T` panicked. - The first bucket of the source `HashMap` contained an entry.
1 parent 274c7bb commit 1fa1dcc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/raw/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
35823582
// cloned so far.
35833583
let mut guard = guard((0, &mut *self), |(index, self_)| {
35843584
if T::NEEDS_DROP {
3585-
for i in 0..=*index {
3585+
for i in 0..*index {
35863586
if self_.is_bucket_full(i) {
35873587
self_.bucket(i).drop();
35883588
}
@@ -3596,7 +3596,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
35963596
to.write(from.as_ref().clone());
35973597

35983598
// Update the index in case we need to unwind.
3599-
guard.0 = index;
3599+
guard.0 = index + 1;
36003600
}
36013601

36023602
// Successfully cloned all items, no need to clean up.

0 commit comments

Comments
 (0)