diff options
author | 2020-03-13 16:50:04 -0500 | |
---|---|---|
committer | 2020-03-25 12:30:15 -0700 | |
commit | b4ebe8432ec7e90cc4a4b5ccfb2c9e131bda3a36 (patch) | |
tree | 449e0e76056d1ba59993e7c0e001c912d6347c75 /src/buf/buf_mut.rs | |
parent | 8bbe9dd87bdf11b1536e56415a39827eeb6d0f3e (diff) | |
download | bytes-b4ebe8432ec7e90cc4a4b5ccfb2c9e131bda3a36.tar.gz bytes-b4ebe8432ec7e90cc4a4b5ccfb2c9e131bda3a36.tar.zst bytes-b4ebe8432ec7e90cc4a4b5ccfb2c9e131bda3a36.zip |
Fix #354 -- Make advance_mut impl of BufMut for Vec<u8> panic if cnt > remaining
Diffstat (limited to 'src/buf/buf_mut.rs')
-rw-r--r-- | src/buf/buf_mut.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs index f5ed2a7..ab9ad18 100644 --- a/src/buf/buf_mut.rs +++ b/src/buf/buf_mut.rs @@ -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); } |