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

fix: usage of BytesMut in extend_buf_sync #369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/stream/buf_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,18 @@ where
R: Read,
{
let size = 8 * 1024;
if !buf.has_remaining_mut() {
if buf.capacity() == buf.len() {
buf.reserve(size);
}

// Copy of tokio's poll_read_buf method (but it has to force initialize the buffer)
let n = {
let bs = buf.chunk_mut();
let bs = buf.spare_capacity_mut();

let initial_size = bs.len().min(size);
let bs = &mut bs[..initial_size];
for i in 0..bs.len() {
bs.write_byte(i, 0);
}
// SAFETY: the above slicing operation guarantees `bs.len() == initial_size`
unsafe { bs.as_mut_ptr().cast::<u8>().write_bytes(0, initial_size) }

// Convert to `&mut [u8]`
// SAFETY: the entire buffer is preinitialized above
Expand Down
Loading