Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsplit an empty but with non-zero capacity BytesMut doesn't work #424

Open
songzhi opened this issue Aug 8, 2020 · 0 comments
Open

Unsplit an empty but with non-zero capacity BytesMut doesn't work #424

songzhi opened this issue Aug 8, 2020 · 0 comments

Comments

@songzhi
Copy link

songzhi commented Aug 8, 2020

let mut bytes = BytesMut::with_capacity(32);
unsafe {
    bytes.set_len(16);
}
let mut rest = bytes.split_off(16);
// unsafe {
//     rest.set_len(8);
// }
println!("{}", rest.capacity()); // 16
bytes.unsplit(rest);
println!("{}", bytes.capacity()); // 16, but it should be 32

if I uncomment rest.set_len(8), the result would be right. I think the following logic is wrong. It just check length, the capacity should be checked too.

bytes/src/bytes_mut.rs

Lines 821 to 824 in 6fdb739

fn try_unsplit(&mut self, other: BytesMut) -> Result<(), BytesMut> {
if other.is_empty() {
return Ok(());
}

@songzhi songzhi changed the title unsplit a empty but with non-zero capacity BytesMut doesn't work Unsplit an empty but with non-zero capacity BytesMut doesn't work Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant