Skip to content

Commit

Permalink
Get rid of uninitialized memory
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Jan 31, 2021
1 parent e0e1a4e commit 8026286
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<T: Read + Seek> 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)
});
Expand Down Expand Up @@ -100,8 +100,7 @@ macro_rules! walue {
type Parameter = usize;

fn read<T: Tape>(tape: &mut T, count: usize) -> Result<Self> {
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)
}
Expand Down

0 comments on commit 8026286

Please # to comment.