diff options
author | 2019-04-03 02:24:30 +0300 | |
---|---|---|
committer | 2019-04-02 16:24:30 -0700 | |
commit | d43e283e5ed520e54df2428f2cf9a7c13c79ff49 (patch) | |
tree | f8d977db52e3962c373d08c3eb7df8cfb431fe43 | |
parent | e0e30f00a1248b1de59405da66cd871ccace4f9f (diff) | |
download | bytes-d43e283e5ed520e54df2428f2cf9a7c13c79ff49.tar.gz bytes-d43e283e5ed520e54df2428f2cf9a7c13c79ff49.tar.zst bytes-d43e283e5ed520e54df2428f2cf9a7c13c79ff49.zip |
Panic in BytesMut::split_to when out of bounds (#252) (#253)v0.4.x
-rw-r--r-- | src/bytes.rs | 2 | ||||
-rw-r--r-- | tests/test_bytes.rs | 9 |
2 files changed, 4 insertions, 7 deletions
diff --git a/src/bytes.rs b/src/bytes.rs index e155931..a9aefa9 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -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), } diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index 4cf340e..e188354 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -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] |