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) });