Skip to content

Commit

Permalink
Merge pull request #303 from Nullus157/fix/panic
Browse files Browse the repository at this point in the history
Fix panic: cannot consume from pending buffer
  • Loading branch information
NobodyXu authored Oct 20, 2024
2 parents 5d4fee2 + 241bee6 commit 014e6e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/futures/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,24 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
State::Flushing
} else {
let mut input = PartialBuffer::new(input);
let done = this.decoder.decode(&mut input, output).or_else(|err| {
let res = this.decoder.decode(&mut input, output).or_else(|err| {
// ignore the first error, occurs when input is empty
// but we need to run decode to flush
if first {
Ok(false)
} else {
Err(err)
}
})?;
});

if !first {
let len = input.written().len();
this.reader.as_mut().consume(len);
}

first = false;

let len = input.written().len();
this.reader.as_mut().consume(len);
if done {
if res? {
State::Flushing
} else {
State::Decoding
Expand Down
13 changes: 8 additions & 5 deletions src/tokio/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,24 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
State::Flushing
} else {
let mut input = PartialBuffer::new(input);
let done = this.decoder.decode(&mut input, output).or_else(|err| {
let res = this.decoder.decode(&mut input, output).or_else(|err| {
// ignore the first error, occurs when input is empty
// but we need to run decode to flush
if first {
Ok(false)
} else {
Err(err)
}
})?;
});

if !first {
let len = input.written().len();
this.reader.as_mut().consume(len);
}

first = false;

let len = input.written().len();
this.reader.as_mut().consume(len);
if done {
if res? {
State::Flushing
} else {
State::Decoding
Expand Down

0 comments on commit 014e6e4

Please sign in to comment.