Skip to content

fix(bytesbuf): correct put_bytes panic docs#496

Open
sandersaares wants to merge 1 commit into
mainfrom
sandersaares/bytesbuf-usize-bound
Open

fix(bytesbuf): correct put_bytes panic docs#496
sandersaares wants to merge 1 commit into
mainfrom
sandersaares/bytesbuf-usize-bound

Conversation

@sandersaares

@sandersaares sandersaares commented Jun 12, 2026

Copy link
Copy Markdown
Member

BytesBuf::put_bytes documented an inapplicable panic condition (insufficient remaining capacity). Appending a BytesView is zero-copy and brings its own backing memory, so it never consumes buffer capacity; its only failure mode is the total length exceeding usize::MAX. The docs now state that.

While investigating, I also confirmed the usize bound only needs an explicit overflow guard on the BytesView side (already present in from_spans_reversed, documented on from_views/append/concat). BytesBuf::from_blocks / from_span_builders operate on exclusively owned memory (Block/SpanBuilder), whose combined capacity is bounded by the virtual address space and can never exceed usize::MAX. Added comments there explaining why no check is needed, contrasting with BytesView's shared, potentially aliased memory.

BytesBuf::put_bytes documented an inapplicable panic condition (insufficient remaining capacity). Appending a BytesView is zero-copy and consumes no capacity, so its only failure mode is the total length exceeding usize::MAX; correct the docs accordingly.

Also add comments to from_blocks/from_span_builders explaining why no overflow check is needed there: they reference exclusively owned memory, whose combined capacity is bounded by the virtual address space and cannot exceed usize::MAX. This bound only needs an explicit guard for BytesView, which references shared memory that may be aliased by multiple views.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sandersaares sandersaares force-pushed the sandersaares/bytesbuf-usize-bound branch from d4993fe to 375b4b5 Compare June 12, 2026 10:58
@sandersaares sandersaares changed the title fix(bytesbuf): enforce and document usize capacity bound fix(bytesbuf): correct put_bytes panic docs Jun 12, 2026
@sandersaares sandersaares marked this pull request as ready for review June 12, 2026 11:02
Copilot AI review requested due to automatic review settings June 12, 2026 11:02
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.9%. Comparing base (963e015) to head (375b4b5).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #496   +/-   ##
=====================================
  Coverage   99.9%   99.9%           
=====================================
  Files        336     336           
  Lines      24829   24829           
=====================================
  Hits       24818   24818           
  Misses        11      11           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR corrects the public documentation for BytesBuf::put_bytes to describe its actual panic condition (length/capacity overflow), reflecting that appending a BytesView is zero-copy and does not require remaining writable capacity in the buffer.

Changes:

  • Update BytesBuf::put_bytes panic docs to describe overflow (> usize::MAX) instead of “insufficient remaining capacity”.
  • Add clarifying comments in BytesBuf::from_blocks / from_span_builders explaining why no overflow guard is required when aggregating exclusively owned Block/SpanBuilder capacity.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/bytesbuf/src/buf.rs Adds explanatory comments about why overflow checks aren’t needed when aggregating exclusively owned capacity sources.
crates/bytesbuf/src/buf_put.rs Fixes put_bytes panic documentation to match the real panic condition (overflow).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

3 participants