set length of vector to max_bytes (closes #345)

This commit is contained in:
ousado 2018-06-25 15:28:43 +02:00 committed by GitHub
parent 800c404c72
commit 0b4954ed79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -440,6 +440,8 @@ impl Stream for ChunkedReadFile {
let max_bytes: usize;
max_bytes = cmp::min(size.saturating_sub(counter), 65_536) as usize;
let mut buf = Vec::with_capacity(max_bytes);
// safe because memory is initialized/overwritten immediately
unsafe { buf.set_len(max_bytes); }
file.seek(io::SeekFrom::Start(offset))?;
let nbytes = file.read(buf.as_mut_slice())?;
if nbytes == 0 {