aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bytes_mut.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs
index c9f5634..0248df8 100644
--- a/src/bytes_mut.rs
+++ b/src/bytes_mut.rs
@@ -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);
}
}