Skip to content
Snippets Groups Projects
Commit 30bd7c1f authored by Dan Burkert's avatar Dan Burkert Committed by Carl Lerche
Browse files

Vec::advance_mut can advance past the end of the buffer (#108)

parent 923d927b
No related branches found
No related tags found
No related merge requests found
...@@ -713,7 +713,7 @@ impl BufMut for Vec<u8> { ...@@ -713,7 +713,7 @@ impl BufMut for Vec<u8> {
if cnt > remaining { if cnt > remaining {
// Reserve additional capacity, and ensure that the total length // Reserve additional capacity, and ensure that the total length
// will not overflow usize. // will not overflow usize.
self.reserve(cnt - remaining); self.reserve(cnt);
} }
self.set_len(len + cnt); self.set_len(len + cnt);
......
...@@ -49,6 +49,17 @@ fn test_put_u16() { ...@@ -49,6 +49,17 @@ fn test_put_u16() {
assert_eq!(b"\x54\x21", &buf[..]); assert_eq!(b"\x54\x21", &buf[..]);
} }
#[test]
fn test_vec_advance_mut() {
// Regression test for carllerche/bytes#108.
let mut buf = Vec::with_capacity(8);
unsafe {
buf.advance_mut(12);
assert_eq!(buf.len(), 12);
assert!(buf.capacity() >= 12, "capacity: {}", buf.capacity());
}
}
#[test] #[test]
fn test_clone() { fn test_clone() {
let mut buf = BytesMut::with_capacity(100); let mut buf = BytesMut::with_capacity(100);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment