From 80262867ec52e8fdb37f3decc3d0e3916949b4b4 Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Sun, 31 Jan 2021 08:57:10 +0100 Subject: [PATCH] Get rid of uninitialized memory --- src/tape.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tape.rs b/src/tape.rs index 8010d43d..8879071b 100644 --- a/src/tape.rs +++ b/src/tape.rs @@ -56,7 +56,7 @@ impl Tape for T {} macro_rules! read( ($tape:ident, $size:expr) => (unsafe { - let mut buffer: [u8; $size] = ::std::mem::uninitialized(); + let mut buffer: [u8; $size] = ::std::mem::zeroed(); ::std::io::Read::read_exact($tape, &mut buffer)?; ::std::mem::transmute(buffer) }); @@ -100,8 +100,7 @@ macro_rules! walue { type Parameter = usize; fn read(tape: &mut T, count: usize) -> Result { - let mut buffer = Vec::with_capacity(count); - unsafe { buffer.set_len(count) }; + let mut buffer = vec![0; count]; ::std::io::Read::read_exact(tape, &mut buffer)?; Ok(buffer) }