Panic in BytesMut::split_to when out of bounds (#252) (#253)

This commit is contained in:
Pavel Strakhov
2019-04-03 02:24:30 +03:00
committed by Carl Lerche
parent b2c5c88732
commit ec1e70f44e
2 changed files with 4 additions and 7 deletions
+2
View File
@@ -1265,6 +1265,8 @@ impl BytesMut {
///
/// Panics if `at > len`.
pub fn split_to(&mut self, at: usize) -> BytesMut {
assert!(at <= self.len());
BytesMut {
inner: self.inner.split_to(at),
}
+2 -7
View File
@@ -258,15 +258,10 @@ fn split_to_oob_mut() {
}
#[test]
#[should_panic]
fn split_to_uninitialized() {
let mut bytes = BytesMut::with_capacity(1024);
let other = bytes.split_to(128);
assert_eq!(bytes.len(), 0);
assert_eq!(bytes.capacity(), 896);
assert_eq!(other.len(), 0);
assert_eq!(other.capacity(), 128);
let _other = bytes.split_to(128);
}
#[test]