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).
This commit is contained in:
Tobin C. Harding 2024-08-30 02:59:01 +10:00
parent cfb53c7866
commit 798c9cff1c
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 1 additions and 1 deletions

View File

@ -78,7 +78,7 @@ mod safety_boundary {
assert!(new_len <= CAP, "buffer overflow");
// SAFETY: MaybeUninit<T> has the same layout as T
let slice = unsafe { &*(slice as *const _ as *const [MaybeUninit<T>]) };
self.data[self.len..].copy_from_slice(slice);
self.data[self.len..new_len].copy_from_slice(slice);
self.len = new_len;
}
}