Skip to content

Handle zero input in public bit-clearing helpers - #143

Open
mikamikasuki wants to merge 1 commit into
petgraph:masterfrom
mikamikasuki:fix/zero-bit-helper-underflow
Open

mikamikasuki wants to merge 1 commit into
petgraph:masterfrom
mikamikasuki:fix/zero-bit-helper-underflow

Conversation

@mikamikasuki

Copy link
Copy Markdown

Calling Ones::last_positive_bit_and_unset or IntoOnes::last_positive_bit_and_unset with zero panics on subtraction in debug builds, while release builds return the block width and leave zero unchanged. Use wrapping subtraction so both builds return the same result, and document the zero-input behavior.

Adds regressions for both helpers covering zero, every single-bit position, and repeated removal from an all-ones block.

Validation: all-features debug and release tests, no-default-features tests, doc tests, formatting, Clippy, and a wasm32 no-default-features build. One existing allocation-abort test was excluded after reproducing its failure on the baseline; all remaining tests pass. Both new tests fail on the baseline in debug mode and pass in release mode.

Fixes #132.

Prepared with AI assistance.

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.

error "attempt to subtract with overflow"

1 participant