about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-06-19 23:10:55 +0000
committerbors <bors@rust-lang.org>2021-06-19 23:10:55 +0000
commitf639657fe4a16ec7704e0af77d0e5d5f587b59df (patch)
treea7c164ff5a4367aff4fe181e3d30408aee91a1a2
parent150fad30ea25e812d481a784d02c95d3394b234b (diff)
parentd8530d0fa31224a2506a0932af5ac18d86c1bb0f (diff)
downloadrust-f639657fe4a16ec7704e0af77d0e5d5f587b59df.tar.gz
rust-f639657fe4a16ec7704e0af77d0e5d5f587b59df.zip
Auto merge of #86433 - paolobarbolini:string-overlapping, r=m-ou-se
Use `copy_nonoverlapping` to copy `bytes` in `String::insert_bytes`

The second copy could be made using `ptr::copy_nonoverlapping` instead of `ptr::copy`, since aliasing won't allow `self` and `bytes` to overlap. LLVM even seems to recognize this, [replacing the second `memmove` with a `memcopy`](https://rust.godbolt.org/z/Yoaa6rrGn), so this makes it so it's always applied.
-rw-r--r--library/alloc/src/string.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index 93f5fe45cd6..a34f530762d 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -1451,7 +1451,7 @@ impl String {
 
         unsafe {
             ptr::copy(self.vec.as_ptr().add(idx), self.vec.as_mut_ptr().add(idx + amt), len - idx);
-            ptr::copy(bytes.as_ptr(), self.vec.as_mut_ptr().add(idx), amt);
+            ptr::copy_nonoverlapping(bytes.as_ptr(), self.vec.as_mut_ptr().add(idx), amt);
             self.vec.set_len(len + amt);
         }
     }