parent
461462dcb3
commit
f1242022c7
@ -0,0 +1,36 @@
|
||||
From 1fa1dcca990d4e9d112f154c83802167f69f4fe9 Mon Sep 17 00:00:00 2001
|
||||
From: Amanieu d'Antras <amanieu@gmail.com>
|
||||
Date: Mon, 4 Mar 2024 17:38:02 +0000
|
||||
Subject: [PATCH] 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.
|
||||
---
|
||||
src/raw/mod.rs | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/raw/mod.rs b/src/raw/mod.rs
|
||||
index ddd4fe7c1..22c01f5e9 100644
|
||||
--- a/src/raw/mod.rs
|
||||
+++ b/src/raw/mod.rs
|
||||
@@ -3582,7 +3582,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
|
||||
// cloned so far.
|
||||
let mut guard = guard((0, &mut *self), |(index, self_)| {
|
||||
if T::NEEDS_DROP {
|
||||
- for i in 0..=*index {
|
||||
+ for i in 0..*index {
|
||||
if self_.is_bucket_full(i) {
|
||||
self_.bucket(i).drop();
|
||||
}
|
||||
@@ -3596,7 +3596,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
|
||||
to.write(from.as_ref().clone());
|
||||
|
||||
// Update the index in case we need to unwind.
|
||||
- guard.0 = index;
|
||||
+ guard.0 = index + 1;
|
||||
}
|
||||
|
||||
// Successfully cloned all items, no need to clean up.
|
Loading…
Reference in new issue