From ddfb00935164211ccca4ee1394154995408e4a96 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Wed, 20 Feb 2019 08:15:26 +1300 Subject: [PATCH] Zero initialize Vec returned from mp4parse_falliable branch of allocate_read_buf. Also delete vec_reserve, which is completely unused. Closes #172. --- mp4parse/src/lib.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/mp4parse/src/lib.rs b/mp4parse/src/lib.rs index 36a83feb..c820c6ef 100644 --- a/mp4parse/src/lib.rs +++ b/mp4parse/src/lib.rs @@ -42,8 +42,8 @@ const BUF_SIZE_LIMIT: usize = 1024 * 1024; // frame per table entry in 30 fps. const TABLE_SIZE_LIMIT: u32 = 30 * 60 * 60 * 24 * 7; -// TODO: vec_push() and vec_reserve() needs to be replaced when Rust supports -// fallible memory allocation in raw_vec. +// TODO: vec_push() needs to be replaced when Rust supports fallible memory +// allocation in raw_vec. #[allow(unreachable_code)] pub fn vec_push(vec: &mut Vec, val: T) -> std::result::Result<(), ()> { #[cfg(feature = "mp4parse_fallible")] @@ -55,24 +55,16 @@ pub fn vec_push(vec: &mut Vec, val: T) -> std::result::Result<(), ()> { Ok(()) } -#[allow(unreachable_code)] -pub fn vec_reserve(vec: &mut Vec, size: usize) -> std::result::Result<(), ()> { - #[cfg(feature = "mp4parse_fallible")] - { - return FallibleVec::try_reserve(vec, size); - } - - vec.reserve(size); - Ok(()) -} - #[allow(unreachable_code)] fn allocate_read_buf(size: usize) -> std::result::Result, ()> { #[cfg(feature = "mp4parse_fallible")] { let mut buf: Vec = Vec::new(); FallibleVec::try_reserve(&mut buf, size)?; - unsafe { buf.set_len(size); } + unsafe { + buf.set_len(size); + std::ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len() * std::mem::size_of::()); + } return Ok(buf); }