Skip to content

Commit d43e283

Browse files
Riatechecarllerche
authored andcommitted
Panic in BytesMut::split_to when out of bounds (#252) (#253)
1 parent e0e30f0 commit d43e283

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/bytes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,8 @@ impl BytesMut {
12651265
///
12661266
/// Panics if `at > len`.
12671267
pub fn split_to(&mut self, at: usize) -> BytesMut {
1268+
assert!(at <= self.len());
1269+
12681270
BytesMut {
12691271
inner: self.inner.split_to(at),
12701272
}

tests/test_bytes.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,10 @@ fn split_to_oob_mut() {
258258
}
259259

260260
#[test]
261+
#[should_panic]
261262
fn split_to_uninitialized() {
262263
let mut bytes = BytesMut::with_capacity(1024);
263-
let other = bytes.split_to(128);
264-
265-
assert_eq!(bytes.len(), 0);
266-
assert_eq!(bytes.capacity(), 896);
267-
268-
assert_eq!(other.len(), 0);
269-
assert_eq!(other.capacity(), 128);
264+
let _other = bytes.split_to(128);
270265
}
271266

272267
#[test]

0 commit comments

Comments
 (0)