Skip to content

Commit

Permalink
Ensure member_buf / send_buf aren't used while taken
Browse files Browse the repository at this point in the history
`is_empty()` wouldn't catch use-then-clear cases
  • Loading branch information
caio committed Mar 18, 2024
1 parent c24a6cf commit 4c4b684
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,9 @@ where
// that we can keep reusing its already-allocated space.
let mut updates = mem::take(&mut self.member_buf);
self.apply_many(updates.drain(..), &mut runtime)?;
debug_assert!(
self.member_buf.is_empty(),
debug_assert_eq!(
0,
self.member_buf.capacity(),
"member_buf modified while taken"
);
self.member_buf = updates;
Expand Down Expand Up @@ -1385,6 +1386,7 @@ where
.map_err(anyhow::Error::msg)
.map_err(Error::Encode)
{
debug_assert_eq!(0, self.send_buf.capacity(), "send_buf modified while taken");
self.send_buf = buf.into_inner();
return Err(err);
}
Expand Down Expand Up @@ -1476,6 +1478,7 @@ where
runtime.send_to(dst, &data);

// absorb the buf into send_buf so we can reuse its capacity
debug_assert_eq!(0, self.send_buf.capacity(), "send_buf modified while taken");
self.send_buf = data;
Ok(())
}
Expand Down

0 comments on commit 4c4b684

Please sign in to comment.