Skip to content

Commit

Permalink
Truncate tweaks (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar authored Apr 17, 2024
1 parent 327615e commit 4e2c9c0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ impl BytesMut {
/// assert_eq!(buf, b"hello"[..]);
/// ```
pub fn truncate(&mut self, len: usize) {
if len <= self.len() {
if len < self.len() {
unsafe {
// SAFETY: Shrinking the buffer cannot expose uninitialized bytes.
self.set_len(len);
}
}
Expand Down

0 comments on commit 4e2c9c0

Please sign in to comment.