Skip to content

Fix the u8 shift overflow in the buffer_bit_ops benchmark - #11175

Merged
Jefffrey merged 1 commit into
apache:mainfrom
amitvijapur:fix/buffer-bit-ops-bench-shift-overflow
Sep 23, 2026
Merged

Jefffrey merged 1 commit into
apache:mainfrom
amitvijapur:fix/buffer-bit-ops-bench-shift-overflow

Conversation

@amitvijapur

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of #10952.

Rationale for this change

Running the benches once under cargo test --benches (the check #10952 asks for) turns up one bench that cannot even start: buffer_bit_ops panics at line 31 with attempt to shift left with overflow. 0b01010101 << i is assigned into a u8 slot, so the literal infers u8 and the shift overflows for every i >= 8. cargo bench builds in release, where the shift amount is masked and the bench runs, which is why it has never shown up.

What changes are included in this PR?

The two shifts become wrapping_shl, which masks the shift amount the same way release mode does, so the fixture bytes are identical to what the benchmark has been measuring all along (checked for i in 0..64). rustfmt split the expression over three lines.

Are these changes tested?

cargo test -p arrow --features test_utils --bench buffer_bit_ops panics on main and passes here. The byte-identity check was a small standalone program comparing the new expression against the masked semantics of the old one.

Are there any user-facing changes?

No.

`0b01010101 << i` infers u8, so for every i >= 8 the shift overflows.
`cargo bench` masks the shift amount and carries on; `cargo test --benches`
(debug, overflow checks on) panics at line 31 before the first benchmark
runs. `wrapping_shl` masks the same way, so the buffers are byte-identical
to what the release build produces today.

Part of apache#10952
@github-actions github-actions Bot added the arrow Changes to the arrow crate label Sep 22, 2026
@Jefffrey Jefffrey added the development-process Internal changes; PRs with this label are excluded from changelog label Sep 23, 2026
@Jefffrey
Jefffrey merged commit e82873e into apache:main Sep 23, 2026
38 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @amitvijapur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate development-process Internal changes; PRs with this label are excluded from changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants