Skip to content

Commit d8d6a7d

Browse files
committed
Fix uninitialized Cell at unsync::Bump::new
1 parent 0732720 commit d8d6a7d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

static-alloc/src/unsync/bump.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl MemBump {
129129
let ptr = NonNull::new(unsafe { alloc::alloc::alloc(layout) })
130130
.unwrap_or_else(|| alloc::alloc::handle_alloc_error(layout));
131131
let ptr = ptr::slice_from_raw_parts_mut(ptr.as_ptr(), capacity);
132+
unsafe { ptr::write(ptr as *mut Cell<usize>, Cell::new(0)) };
132133
unsafe { alloc::boxed::Box::from_raw(ptr as *mut MemBump) }
133134
}
134135
}
@@ -250,10 +251,7 @@ impl MemBump {
250251
/// This is how many *bytes* can be allocated
251252
/// within this node.
252253
pub const fn capacity(&self) -> usize {
253-
// Safety: just gets the pointer metadata `len` without invalidating any provenance,
254-
// accepting the pointer use itself. This may be replaced by a safe `pointer::len` as soon
255-
// as stable (#71146) and const which would avoid any pointer use.
256-
unsafe { (*(self.data.get() as *const [UnsafeCell<u8>])).len() }
254+
self.data.get().len()
257255
}
258256

259257
/// Get a raw pointer to the data.
@@ -502,7 +500,7 @@ impl MemBump {
502500
let requested = layout.size();
503501

504502
// Ensure no overflows when calculating offets within.
505-
assert!(expect_consumed <= length);
503+
assert!(expect_consumed <= length, "{}/{}", expect_consumed, length);
506504

507505
let available = length.checked_sub(expect_consumed).unwrap();
508506
let ptr_to = base_ptr.wrapping_add(expect_consumed);

0 commit comments

Comments
 (0)