Skip to content

Commit

Permalink
Panic on integer overflow in Chain::remaining (#482)
Browse files Browse the repository at this point in the history
Make it safer.
  • Loading branch information
stepancheg committed Feb 16, 2021
1 parent 268f6f8 commit 2428c15
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 2428c15

Please sign in to comment.