From: Kostya Shishkov Date: Mon, 13 Apr 2020 09:29:08 +0000 (+0200) Subject: core/io: fix bug in MemoryReader::peek_buf() X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=b2939bd867eda60d083199153fb9103fc54426bb;p=nihav.git core/io: fix bug in MemoryReader::peek_buf() --- diff --git a/nihav-core/src/io/byteio.rs b/nihav-core/src/io/byteio.rs index 4463b2b..ba3d95c 100644 --- a/nihav-core/src/io/byteio.rs +++ b/nihav-core/src/io/byteio.rs @@ -472,7 +472,7 @@ impl<'a> ByteIO for MemoryReader<'a> { } fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult { - let copy_size = if self.buf.len() - self.pos < buf.len() { self.buf.len() } else { buf.len() }; + let copy_size = if self.buf.len() - self.pos < buf.len() { self.buf.len() - self.pos } else { buf.len() }; if copy_size == 0 { return Err(ByteIOError::EOF); } let dst = &mut buf[0..copy_size]; dst.copy_from_slice(&self.buf[self.pos..][..copy_size]);