mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Rollup merge of #85610 - SkiFire13:fix-copy-within-provenance, r=oli-obk
Fix pointer provenance in <[T]>::copy_within Previously the `self.as_mut_ptr()` invalidated the pointer created by the first `self.as_ptr()`. This also triggered miri when run with `-Zmiri-track-raw-pointers`
This commit is contained in:
commit
b7b9ce3df8
@ -3096,7 +3096,11 @@ impl<T> [T] {
|
||||
// SAFETY: the conditions for `ptr::copy` have all been checked above,
|
||||
// as have those for `ptr::add`.
|
||||
unsafe {
|
||||
ptr::copy(self.as_ptr().add(src_start), self.as_mut_ptr().add(dest), count);
|
||||
// Derive both `src_ptr` and `dest_ptr` from the same loan
|
||||
let ptr = self.as_mut_ptr();
|
||||
let src_ptr = ptr.add(src_start);
|
||||
let dest_ptr = ptr.add(dest);
|
||||
ptr::copy(src_ptr, dest_ptr, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user