diff options
| author | nathanwhit <nathan.whitaker01@gmail.com> | 2019-07-16 15:41:43 -0400 |
|---|---|---|
| committer | nathanwhit <nathan.whitaker01@gmail.com> | 2019-07-16 22:41:38 -0400 |
| commit | 04f0d309dcbaa8425c702d1439592b87fff0a69e (patch) | |
| tree | 81232fd690bf26100818e6c8b8b1c841c8fae7e2 /src/libstd | |
| parent | d82fd9ecd3e65a313b0e0bdd24de127d4b566156 (diff) | |
| download | rust-04f0d309dcbaa8425c702d1439592b87fff0a69e.tar.gz rust-04f0d309dcbaa8425c702d1439592b87fff0a69e.zip | |
Remove last use of mem::uninitialized from std::io::util
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/util.rs | 13 |
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; |
