Skip to content

Commit 014e6e4

Browse files
authored
Merge pull request #303 from Nullus157/fix/panic
Fix panic: cannot consume from pending buffer
2 parents 5d4fee2 + 241bee6 commit 014e6e4

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/futures/bufread/generic/decoder.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,24 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
8888
State::Flushing
8989
} else {
9090
let mut input = PartialBuffer::new(input);
91-
let done = this.decoder.decode(&mut input, output).or_else(|err| {
91+
let res = this.decoder.decode(&mut input, output).or_else(|err| {
9292
// ignore the first error, occurs when input is empty
9393
// but we need to run decode to flush
9494
if first {
9595
Ok(false)
9696
} else {
9797
Err(err)
9898
}
99-
})?;
99+
});
100+
101+
if !first {
102+
let len = input.written().len();
103+
this.reader.as_mut().consume(len);
104+
}
100105

101106
first = false;
102107

103-
let len = input.written().len();
104-
this.reader.as_mut().consume(len);
105-
if done {
108+
if res? {
106109
State::Flushing
107110
} else {
108111
State::Decoding

src/tokio/bufread/generic/decoder.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,24 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
8888
State::Flushing
8989
} else {
9090
let mut input = PartialBuffer::new(input);
91-
let done = this.decoder.decode(&mut input, output).or_else(|err| {
91+
let res = this.decoder.decode(&mut input, output).or_else(|err| {
9292
// ignore the first error, occurs when input is empty
9393
// but we need to run decode to flush
9494
if first {
9595
Ok(false)
9696
} else {
9797
Err(err)
9898
}
99-
})?;
99+
});
100+
101+
if !first {
102+
let len = input.written().len();
103+
this.reader.as_mut().consume(len);
104+
}
100105

101106
first = false;
102107

103-
let len = input.written().len();
104-
this.reader.as_mut().consume(len);
105-
if done {
108+
if res? {
106109
State::Flushing
107110
} else {
108111
State::Decoding

0 commit comments

Comments
 (0)