Skip to content

Commit 04f0d30

Browse files
committed
Remove last use of mem::uninitialized from std::io::util
1 parent d82fd9e commit 04f0d30

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/libstd/io/util.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<
4444
where R: Read, W: Write
4545
{
4646
let mut buf = unsafe {
47-
#[allow(deprecated)]
48-
let mut buf: [u8; super::DEFAULT_BUF_SIZE] = mem::uninitialized();
49-
reader.initializer().initialize(&mut buf);
50-
buf
47+
// This is still technically undefined behavior due to creating a reference
48+
// to uninitialized data, but within libstd we can rely on more guarantees
49+
// than if this code were in an external lib
50+
51+
// FIXME: This should probably be changed to an array of `MaybeUninit<u8>`
52+
// once the `mem::MaybeUninit` slice APIs stabilize
53+
let mut buf: mem::MaybeUninit<[u8; super::DEFAULT_BUF_SIZE]> = mem::MaybeUninit::uninit();
54+
reader.initializer().initialize(&mut *buf.as_mut_ptr());
55+
buf.assume_init()
5156
};
5257

5358
let mut written = 0;

0 commit comments

Comments
 (0)