Skip to content

Commit 1a03e0d

Browse files
committed
fix(utils): don't const_allocate(0, _)
I noticed that the test code from [the PR constifying `Box`'s methods] [1] avoids calling `const_allocate` with size zero. [1]: https://github.com/rust-lang/rust/pull/91884/files#diff-5ebca97f446e7823021939db776e4dca5563ec3409e55295387553b279b51521R66
1 parent 7ff1316 commit 1a03e0d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/r3_core/src/utils/alloc/allocator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ unsafe impl const rlsf::FlexSource for ConstFlexSource {
394394
return None;
395395
};
396396

397+
assert!(min_size != 0);
398+
397399
// FIXME: Directly calling `const_allocate` from here causes the
398400
// compiler to panic
399401
// Safety: `const_allocate_{in_const, at_rt}` behave observably

src/r3_core/src/utils/alloc/freeze.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ impl<T: Copy> Frozen<T> {
4747
.checked_mul(x.len())
4848
.expect("size overflow");
4949
let align = core::mem::align_of::<T>();
50+
51+
if size == 0 {
52+
return &[];
53+
}
54+
5055
unsafe {
5156
// Allocate a CTFE heap memory block
5257
let ptr = core::intrinsics::const_allocate(size, align).cast::<T>();

0 commit comments

Comments
 (0)