Skip to content

Commit cb122d4

Browse files
committed
Fix panic: cannot consume from pending buffer
Fixed #298 Signed-off-by: Jiahao XU <[email protected]>
1 parent 535fc9c commit cb122d4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/futures/bufread/generic/decoder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,22 @@ 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+
});
100100

101101
first = false;
102102

103103
let len = input.written().len();
104104
this.reader.as_mut().consume(len);
105-
if done {
105+
106+
if res? {
106107
State::Flushing
107108
} else {
108109
State::Decoding

src/tokio/bufread/generic/decoder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,22 @@ 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+
});
100100

101101
first = false;
102102

103103
let len = input.written().len();
104104
this.reader.as_mut().consume(len);
105-
if done {
105+
106+
if res? {
106107
State::Flushing
107108
} else {
108109
State::Decoding

0 commit comments

Comments
 (0)