mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-11 00:00:23 +02:00
Fix #354 -- Make advance_mut impl of BufMut for Vec<u8> panic if cnt > remaining
This commit is contained in:
committed by
Sean McArthur
parent
8bbe9dd87b
commit
b4ebe8432e
+7
-5
@@ -990,11 +990,13 @@ impl BufMut for Vec<u8> {
|
||||
unsafe fn advance_mut(&mut self, cnt: usize) {
|
||||
let len = self.len();
|
||||
let remaining = self.capacity() - len;
|
||||
if cnt > remaining {
|
||||
// Reserve additional capacity, and ensure that the total length
|
||||
// will not overflow usize.
|
||||
self.reserve(cnt);
|
||||
}
|
||||
|
||||
assert!(
|
||||
cnt <= remaining,
|
||||
"cannot advance past `remaining_mut`: {:?} <= {:?}",
|
||||
cnt,
|
||||
remaining
|
||||
);
|
||||
|
||||
self.set_len(len + cnt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user