aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Brad Dunbar <dunbarb2@gmail.com> 2024-04-17 05:27:00 -0400
committerGravatar GitHub <noreply@github.com> 2024-04-17 11:27:00 +0200
commit4e2c9c065a06bf9cb5d7dd46e3b29f62a1c20057 (patch)
tree02e3b81cd7bff10fb89919e7a773d17badd8971b
parent327615e5d4ba27e9647734d83ef9ad88d7dd8a38 (diff)
downloadbytes-4e2c9c065a06bf9cb5d7dd46e3b29f62a1c20057.tar.gz
bytes-4e2c9c065a06bf9cb5d7dd46e3b29f62a1c20057.tar.zst
bytes-4e2c9c065a06bf9cb5d7dd46e3b29f62a1c20057.zip
Truncate tweaks (#694)
-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);
}
}