fix some slicing issues

This commit is contained in:
Szymon Walter 2018-03-19 17:41:42 +01:00
parent 1d8b1466ff
commit 2e336270c8

View file

@ -306,11 +306,13 @@ mod file {
range: Range<usize>, range: Range<usize>,
) -> BufferSlice<'a, u8> { ) -> BufferSlice<'a, u8> {
let index = range.start; 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(); let mut refmut = self.borrow_mut();
refmut refmut
.seek(SeekFrom::Start(index as u64)) .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| { .unwrap_or_else(|err| {
panic!("could't read from File Buffer: {:?}", err) panic!("could't read from File Buffer: {:?}", err)
}); });