Skip to content

Commit

Permalink
Panic on integer overflow in Chain::remaining (tokio-rs#482)
Browse files Browse the repository at this point in the history
Make it safer.
  • Loading branch information
stepancheg authored and lelongg committed Jan 9, 2023
1 parent d8d398b commit 840c9aa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/buf/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
U: Buf,
{
fn remaining(&self) -> usize {
self.a.remaining() + self.b.remaining()
self.a.remaining().checked_add(self.b.remaining()).unwrap()
}

fn chunk(&self) -> &[u8] {
Expand Down Expand Up @@ -178,7 +178,10 @@ where
U: BufMut,
{
fn remaining_mut(&self) -> usize {
self.a.remaining_mut() + self.b.remaining_mut()
self.a
.remaining_mut()
.checked_add(self.b.remaining_mut())
.unwrap()
}

fn chunk_mut(&mut self) -> &mut UninitSlice {
Expand Down

0 comments on commit 840c9aa

Please sign in to comment.