Skip to content

Commit

Permalink
Fix passing uninit buffer to user-provided Read implementation
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
andrewhickman committed Jan 29, 2021
1 parent d583d52 commit 599313b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/read.rs
Expand Up @@ -17,12 +17,9 @@ impl<R: io::Read> IoReader<R> {

impl<R: io::Read> BufReadExact for IoReader<R> {
fn buf_read_exact(&mut self, len: usize) -> io::Result<&[u8]> {
unsafe {
self.buf.reserve(len);
let slice = self.buf.get_unchecked_mut(..len);
self.rdr.read_exact(slice)?;
Ok(slice)
}
self.buf.resize(len, 0);
self.rdr.read_exact(self.buf.as_mut_slice())?;
Ok(self.buf.as_slice())
}
}

Expand Down

0 comments on commit 599313b

Please sign in to comment.