From 798c9cff1c9e85bbfbb41a0f80336b7391b41a45 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 30 Aug 2024 02:59:01 +1000 Subject: [PATCH] Fix bug in ArrayVec::extend_from_slice Currently the source slice must be the exact length to fill the array to max capacity, this is an unnecessary restriction since an `ArrayVec` is a variable sized data structure. Set the destination slice to be the same length as the source slice (still maintain capacity checks). --- internals/src/array_vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internals/src/array_vec.rs b/internals/src/array_vec.rs index f75924ba1..8b6e54bf2 100644 --- a/internals/src/array_vec.rs +++ b/internals/src/array_vec.rs @@ -78,7 +78,7 @@ mod safety_boundary { assert!(new_len <= CAP, "buffer overflow"); // SAFETY: MaybeUninit has the same layout as T let slice = unsafe { &*(slice as *const _ as *const [MaybeUninit]) }; - self.data[self.len..].copy_from_slice(slice); + self.data[self.len..new_len].copy_from_slice(slice); self.len = new_len; } }