|
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> { |
|
let new_ptr = self.ptr.checked_sub(layout.size()).ok_or(AllocErr)?; |
|
let aligned_ptr = new_ptr & !(layout.align() - 1); |
|
|
|
if unlikely(aligned_ptr < self.start()) { |
|
return Err(AllocErr); |
|
} |
|
|
|
let memory = self.create_block(aligned_ptr)?; |
|
unsafe { init.init(memory) }; |
|
Ok(memory) |
These lines return part of the data as a MemoryBlock. This unsafe operation permits the caller to write uninitialized bytes to that region. It's not yet clear if it is UB to do that. In any case it is a safety invariant so you mustn't leak this uninitialized state after your borrow of data has ended but there is no Drop implementation that would take care of it.
alloc-compose/src/region.rs
Lines 86 to 96 in 375d762
These lines return part of the
dataas aMemoryBlock. This unsafe operation permits the caller to write uninitialized bytes to that region. It's not yet clear if it is UB to do that. In any case it is a safety invariant so you mustn't leak this uninitialized state after your borrow ofdatahas ended but there is no Drop implementation that would take care of it.