Skip to content

Commit

Permalink
Don't leave Decoder in invalid state if read fails
Browse files Browse the repository at this point in the history
If a read fails, such as in the case of non-blocking IO, we don't want
to leave the Decoder in an invalid state.  Only change the state of the
Decoder if a read succeeds, otherwise, allow for calling again.
  • Loading branch information
bvinc committed Jun 12, 2016
1 parent 77e89fd commit 578be4a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/decoder.rs
Expand Up @@ -58,7 +58,6 @@ impl<R: Read> Read for Decoder<R> {
let mut dst_offset: usize = 0;
while dst_offset == 0 {
if self.pos >= self.len {
self.pos = 0;
let need = match self.buf.len() < self.next {
true => self.buf.len(),
false => self.next,
Expand All @@ -67,6 +66,7 @@ impl<R: Read> Read for Decoder<R> {
if self.len <= 0 {
break;
}
self.pos = 0;
self.next -= self.len;
}
while (dst_offset < buf.len()) && (self.pos < self.len) {
Expand Down

0 comments on commit 578be4a

Please sign in to comment.