From 04f0d309dcbaa8425c702d1439592b87fff0a69e Mon Sep 17 00:00:00 2001 From: nathanwhit Date: Tue, 16 Jul 2019 15:41:43 -0400 Subject: [PATCH] Remove last use of mem::uninitialized from std::io::util --- src/libstd/io/util.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 2bfd3e4ad20e3..1efccb53b7551 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -44,10 +44,15 @@ pub fn copy(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` + // 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;