Skip to content

Commit 4e2c9c0

Browse files
authored
Truncate tweaks (#694)
1 parent 327615e commit 4e2c9c0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/bytes_mut.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,9 @@ impl BytesMut {
422422
/// assert_eq!(buf, b"hello"[..]);
423423
/// ```
424424
pub fn truncate(&mut self, len: usize) {
425-
if len <= self.len() {
425+
if len < self.len() {
426426
unsafe {
427+
// SAFETY: Shrinking the buffer cannot expose uninitialized bytes.
427428
self.set_len(len);
428429
}
429430
}

0 commit comments

Comments
 (0)