about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-07-18 11:29:45 -0400
committerGitHub <noreply@github.com>2019-07-18 11:29:45 -0400
commit5d4681f76a700117c01b6203edfd6ff02e36ddab (patch)
treef7bf7d5cf5ac9e223af57043c8fbe4608a2ebe7a /src/libstd
parentaa31ca71283f783b20ee3b460620e0907f4a4a31 (diff)
parent04f0d309dcbaa8425c702d1439592b87fff0a69e (diff)
downloadrust-5d4681f76a700117c01b6203edfd6ff02e36ddab.tar.gz
rust-5d4681f76a700117c01b6203edfd6ff02e36ddab.zip
Rollup merge of #62732 - nathanwhit:fix_mem_uninit, r=Amanieu
Remove last use of mem::uninitialized from std::io::util

Addresses #62397 for std::io::util
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/util.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs
index 2bfd3e4ad20..1efccb53b75 100644
--- a/src/libstd/io/util.rs
+++ b/src/libstd/io/util.rs
@@ -44,10 +44,15 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<
     where R: Read, W: Write
 {
     let mut buf = unsafe {
-        #[allow(deprecated)]
-        let mut buf: [u8; super::DEFAULT_BUF_SIZE] = mem::uninitialized();
-        reader.initializer().initialize(&mut buf);
-        buf
+        // This is still technically undefined behavior due to creating a reference
+        // to uninitialized data, but within libstd we can rely on more guarantees
+        // than if this code were in an external lib
+
+        // FIXME: This should probably be changed to an array of `MaybeUninit<u8>`
+        // once the `mem::MaybeUninit` slice APIs stabilize
+        let mut buf: mem::MaybeUninit<[u8; super::DEFAULT_BUF_SIZE]> = mem::MaybeUninit::uninit();
+        reader.initializer().initialize(&mut *buf.as_mut_ptr());
+        buf.assume_init()
     };
 
     let mut written = 0;