Skip to content

Handle allocation failure and zero-sized types - #17

Merged
droundy merged 1 commit into
mainfrom
fix-alloc-bugs
Oct 18, 2026
Merged

droundy merged 1 commit into
mainfrom
fix-alloc-bugs

Conversation

@droundy

@droundy droundy commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Two pre-existing undefined-behavior bugs in pre_push:

  • Allocation failure: the pointer from alloc was written through without a null check. It now calls handle_alloc_error, as Vec does.
  • Zero-sized types: for AppendOnlyVec<()> (or any ZST) every bin layout has size zero, and alloc/dealloc with a zero-size layout is UB. Miri reports creating allocation with size 0 on main. These bins now use NonNull::dangling() and Drop skips freeing them.

Adds test_zero_sized, which fails under cargo +nightly miri test before this change and passes after.

These matter more once #16 lands, since embedded heaps are small enough for allocation failure to be realistic.

🤖 Generated with Claude Code

pre_push wrote through the pointer returned by alloc without checking
for null, so an allocation failure was undefined behavior.  It now
calls handle_alloc_error.

For a zero-sized T the bin layouts have size zero, and calling alloc
or dealloc with a zero-size layout is undefined behavior (Miri reports
it).  We now use a dangling pointer for those bins and never free it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@droundy
droundy merged commit 6313619 into main Oct 18, 2026
18 of 20 checks passed
droundy added a commit that referenced this pull request Oct 18, 2026
Resolve conflicts with #17 by keeping its allocation-failure and
zero-sized-type handling, using core/alloc paths instead of std.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@droundy droundy mentioned this pull request Oct 18, 2026
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