Skip to content

Zero initialize Vec returned from mp4parse_fallible branch of allocate_read_buf. #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions mp4parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(vec: &mut Vec<T>, val: T) -> std::result::Result<(), ()> {
#[cfg(feature = "mp4parse_fallible")]
Expand All @@ -55,24 +55,13 @@ pub fn vec_push<T>(vec: &mut Vec<T>, val: T) -> std::result::Result<(), ()> {
Ok(())
}

#[allow(unreachable_code)]
pub fn vec_reserve<T>(vec: &mut Vec<T>, 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<Vec<u8>, ()> {
#[cfg(feature = "mp4parse_fallible")]
{
let mut buf: Vec<u8> = Vec::new();
FallibleVec::try_reserve(&mut buf, size)?;
unsafe { buf.set_len(size); }
buf.extend(std::iter::repeat(0).take(size));
return Ok(buf);
}

Expand Down