diff --git a/varint-rs/src/lib.rs b/varint-rs/src/lib.rs index 5529c41c..ed508bb0 100644 --- a/varint-rs/src/lib.rs +++ b/varint-rs/src/lib.rs @@ -378,8 +378,12 @@ impl Decoder for VarintDecoder { fn decode(&mut self, src: &mut BytesMut) -> Result, Self::Error> { loop { - if src.is_empty() && self.state.is_some() { - break Err(io::Error::from(io::ErrorKind::UnexpectedEof)); + if src.is_empty() { + if self.state.is_some() { + break Err(io::Error::from(io::ErrorKind::UnexpectedEof)); + } else { + break Ok(None); + } } else { // We know that the length is not 0, so this cannot fail. let first_byte = src.split_to(1)[0]; @@ -633,4 +637,12 @@ mod tests { assert_eq!(result.unwrap_err().kind(), io::ErrorKind::UnexpectedEof); } + + #[test] + fn no_panic_after_eof() { + FramedRead::new(&[1, 1][..], VarintDecoder::::new()) + .collect() + .wait() + .unwrap(); + } }