From 0e4b046279fb1109d185099fb3c6b24baf7baf89 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_fallable branch of allocate_read_buf. Also delete vec_reserve, which is completely unused. Closes #172. --- mp4parse/src/lib.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/mp4parse/src/lib.rs b/mp4parse/src/lib.rs index 36a83feb..d466fa1d 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,13 @@ 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); } + buf.extend(std::iter::repeat(0).take(size)); return Ok(buf); }