From 2e336270c89ce49d405df7863b4e13701504bd2c Mon Sep 17 00:00:00 2001 From: Szymon Walter Date: Mon, 19 Mar 2018 17:41:42 +0100 Subject: [PATCH] fix some slicing issues --- src/buffer/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 9051e66..6a7d137 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -306,11 +306,13 @@ mod file { range: Range, ) -> BufferSlice<'a, u8> { let index = range.start; - let mut vec = Vec::with_capacity(range.end - range.start); + let len = range.end - range.start; + let mut vec = Vec::with_capacity(len); + vec.set_len(len); let mut refmut = self.borrow_mut(); refmut .seek(SeekFrom::Start(index as u64)) - .and_then(|_| refmut.read_exact(&mut vec[range])) + .and_then(|_| refmut.read_exact(&mut vec[..])) .unwrap_or_else(|err| { panic!("could't read from File Buffer: {:?}", err) });