Skip to content

Commit

Permalink
Improve readability of alloc_ptr helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Oct 12, 2023
1 parent c34bddc commit 67e2e04
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,15 @@ impl TypeMetadataSet {
}

fn alloc_ptr(layout: Layout) -> *mut u8 {
let ptr = if layout.size() != 0 {
unsafe { alloc(layout) }
} else {
invalid_ptr(layout.align())
};

if !ptr.is_null() {
ptr
} else {
if layout.size() == 0 {
return invalid_ptr(layout.align());
}

let ptr = unsafe { alloc(layout) };
if ptr.is_null() {
handle_alloc_error(layout);
}
ptr
}

fn invalid_ptr(addr: usize) -> *mut u8 {
Expand Down

0 comments on commit 67e2e04

Please sign in to comment.