Merge rust-bitcoin/rust-bitcoin#3272: Fix bug in `ArrayVec::extend_from_slice`
4024ba5910
Add unit test for ArrayVec::extend_from_slice (Tobin C. Harding)798c9cff1c
Fix bug in ArrayVec::extend_from_slice (Tobin C. Harding) Pull request description: 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). ACKs for top commit: Kixunil: ACK4024ba5910
apoelstra: ACK4024ba5910
successfully ran local tests Tree-SHA512: b7a510ba6f6e5cf5a535d691f79da98e29558eb9a50b60d41e080769560e9b9f0b8a831806dc9f159c888001951e17b5bbd970363d6a2e57fa9748902548b3ab
This commit is contained in:
commit
904fefba5a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -181,4 +181,10 @@ mod tests {
|
|||
let mut av = ArrayVec::<_, 0>::new();
|
||||
av.extend_from_slice(&[42]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extend_from_slice() {
|
||||
let mut av = ArrayVec::<u8, 8>::new();
|
||||
av.extend_from_slice(b"abc");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue