Skip to content

fix: BytesMut only reuse if src has remaining - #803

Merged
Darksonn merged 5 commits into
tokio-rs:masterfrom
discord9:fix/copy_to_bytes
Nov 14, 2025
Merged

Darksonn merged 5 commits into
tokio-rs:masterfrom
discord9:fix/copy_to_bytes

Conversation

@discord9

@discord9 discord9 commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

prevent stack overflow in this case:

let mut buf = BytesMut::new();
buf.put(&[] as &[u8]);

closes #802

Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
@discord9 discord9 changed the title fix: default impl of Buf Nov 14, 2025
@discord9

Copy link
Copy Markdown
Contributor Author

@paolobarbolini is this fix reasonable?

@Darksonn Darksonn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this!

Overall looks good, but I have a suggested alternative implementation.

Comment thread src/bytes_mut.rs Outdated
Comment thread src/bytes_mut.rs Outdated
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>

@Darksonn Darksonn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@Darksonn
Darksonn merged commit 60cbb77 into tokio-rs:master Nov 14, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants