Skip to content

fix(util): fix off-by-one slice and missing block handling in ReadIOAdapter - #96

Open
Adityakk9031 wants to merge 1 commit into
context-dot-dev:mainfrom
Adityakk9031:fix/read-io-adapter-bugs
Open

Adityakk9031 wants to merge 1 commit into
context-dot-dev:mainfrom
Adityakk9031:fix/read-io-adapter-bugs

Conversation

@Adityakk9031

@Adityakk9031 Adityakk9031 commented Oct 24, 2026 •

Copy link
Copy Markdown

While inspecting ReadIOAdapter, noticed two issues with chunk reads:

  1. read_enum was using slice!(..max_len), which takes an inclusive range (0..max_len) and ends up reading max_len + 1 bytes when there are enough bytes buffered. Switching this to slice!(0, max_len) ensures we don't exceed the requested length.
  2. In read, .tap(&@blk) blows up with LocalJumpError (no block given) if the adapter was initialized without a block. Using .tap { @blk&.call(_1) } avoids yielding nil.

Added a couple of unit tests covering chunked reads and blockless initialization.

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.

1 participant