Fix miri error in extend_zst
Miri reported this here: Undefined Behavior: memory access failed: alloc42975 has size 4, so pointer at offset 5 is out-of-bounds specifically for the ptr.write() where ptr is a pointer to ZST. Somewhat confusing that miri complains about the write, maybe a new feature.
This commit is contained in:
+3
-1
@@ -1088,7 +1088,9 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
|
|||||||
if let Some(elt) = iter.next() {
|
if let Some(elt) = iter.next() {
|
||||||
if ptr == end_ptr && CHECK { extend_panic(); }
|
if ptr == end_ptr && CHECK { extend_panic(); }
|
||||||
debug_assert_ne!(ptr, end_ptr);
|
debug_assert_ne!(ptr, end_ptr);
|
||||||
|
if mem::size_of::<T>() != 0 {
|
||||||
ptr.write(elt);
|
ptr.write(elt);
|
||||||
|
}
|
||||||
ptr = raw_ptr_add(ptr, 1);
|
ptr = raw_ptr_add(ptr, 1);
|
||||||
guard.data += 1;
|
guard.data += 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -1115,7 +1117,7 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
|
|||||||
unsafe fn raw_ptr_add<T>(ptr: *mut T, offset: usize) -> *mut T {
|
unsafe fn raw_ptr_add<T>(ptr: *mut T, offset: usize) -> *mut T {
|
||||||
if mem::size_of::<T>() == 0 {
|
if mem::size_of::<T>() == 0 {
|
||||||
// Special case for ZST
|
// Special case for ZST
|
||||||
ptr.cast::<u8>().wrapping_add(offset).cast()
|
ptr.cast::<u8>().wrapping_add(offset).cast::<T>()
|
||||||
} else {
|
} else {
|
||||||
ptr.add(offset)
|
ptr.add(offset)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user