Skip to content

Commit a571e27

Browse files
uefi: Fix unsafe_op_in_unsafe_fn in allocator module
1 parent a9788a3 commit a571e27

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

uefi/src/allocator.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ unsafe impl GlobalAlloc for Allocator {
9090
// write is appropriately aligned for a `*mut u8` pointer because
9191
// `align_ptr` is aligned, and alignments are always powers of two
9292
// (as enforced by the `Layout` type).
93-
let aligned_ptr = full_alloc_ptr.add(offset);
94-
(aligned_ptr.cast::<*mut u8>()).sub(1).write(full_alloc_ptr);
95-
aligned_ptr
93+
unsafe {
94+
let aligned_ptr = full_alloc_ptr.add(offset);
95+
(aligned_ptr.cast::<*mut u8>()).sub(1).write(full_alloc_ptr);
96+
aligned_ptr
97+
}
9698
} else {
9799
// The requested alignment is less than or equal to eight, and
98100
// `allocate_pool` always provides eight-byte alignment, so we can
@@ -108,13 +110,13 @@ unsafe impl GlobalAlloc for Allocator {
108110
if layout.align() > 8 {
109111
// Retrieve the pointer to the full allocation that was packed right
110112
// before the aligned allocation in `alloc`.
111-
ptr = (ptr as *const *mut u8).sub(1).read();
113+
ptr = unsafe { (ptr as *const *mut u8).sub(1).read() };
112114
}
113115

114116
// OK to unwrap: `ptr` is required to be a valid allocation by the trait API.
115117
let ptr = NonNull::new(ptr).unwrap();
116118

117119
// Warning: this will panic after exiting boot services.
118-
boot::free_pool(ptr).unwrap();
120+
unsafe { boot::free_pool(ptr) }.unwrap();
119121
}
120122
}

0 commit comments

Comments
 (0)