We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b724914 commit d1b5d4cCopy full SHA for d1b5d4c
src/bytes_mut.rs
@@ -705,6 +705,15 @@ impl BytesMut {
705
new_cap = cmp::max(double, new_cap);
706
707
// No space - allocate more
708
+ //
709
+ // The length field of `Shared::vec` is not used by the `BytesMut`;
710
+ // instead we use the `len` field in the `BytesMut` itself. However,
711
+ // when calling `reserve`, it doesn't guarantee that data stored in
712
+ // the unused capacity of the vector is copied over to the new
713
+ // allocation, so we need to ensure that we don't have any data we
714
+ // care about in the unused capacity before calling `reserve`.
715
+ debug_assert!(off + len <= v.capacity());
716
+ v.set_len(off + len);
717
v.reserve(new_cap - v.len());
718
719
// Update the info
0 commit comments