Skip to content

Fix overflow/underflow bugs in bitset allocator, RtServer replenish, and IndexMap iterator#49

Draft
Copilot wants to merge 2 commits intofix/misc-bugsfrom
copilot/sub-pr-47
Draft

Fix overflow/underflow bugs in bitset allocator, RtServer replenish, and IndexMap iterator#49
Copilot wants to merge 2 commits intofix/misc-bugsfrom
copilot/sub-pr-47

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 4, 2026

Four arithmetic bugs exposed by panicking tests, covering integer overflow and underflow in the PFA bitset allocator marking phase, RT budget replenishment, and the IndexMap cycle iterator.

Fixes

  • bitset.rs marking underflowrem = len.min(BITS_PER_WORD) - skip underflowed when a free run started at the last bit of a word (skip=63, len=11 - 63). Replaced with rem = (BITS_PER_WORD - skip).min(count) using a dedicated count = page_count variable for the marking loop, keeping search-phase len untouched.

  • thread.rs replenish overflowbudget_left += budget overflowed when both values approached u32::MAX. Changed to saturating_add.

  • array.rs iter_from_cycle / next() overflowK::to_index(idx) + 1 panicked when idx = usize::MAX. Fixed with .wrapping_add(1) % N in iter_from_cycle and the same wrapping arithmetic in the next() index computation.

  • array.rs reserve() OOM in testsreserve() legitimately needs to grow extra heap storage (e.g. len=7, N=8, additional=2 requires 1 extra slot), but GLOBAL_ALLOCATOR is uninitialized in the test environment. Added #[cfg(test)] pub(crate) init_test_heap() to mem.rs that seeds the global allocator with 64 KiB of host memory via std::alloc::alloc, called from the affected test.

Agent-Logs-Url: https://github.com/OsirisRTOS/osiris/sessions/f63a1358-2cfb-4d9d-8ada-ddd2c84eff6f

Co-authored-by: xarantolus <32465636+xarantolus@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Apr 4, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Copilot AI changed the title [WIP] Fix different over/underflow bugs Fix overflow/underflow bugs in bitset allocator, RtServer replenish, and IndexMap iterator Apr 4, 2026
Copilot AI requested a review from xarantolus April 4, 2026 15:16
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.

2 participants