Skip to content

Commit 0ccc1aa

Browse files
uefi: Improve Align implementation
Replace some `as usize` code with `ptr::align_offset`.
1 parent 604a03c commit 0ccc1aa

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

uefi/src/data_types/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,15 @@ pub trait Align {
121121
/// is aligned. Returns `None` if no element of the buffer is
122122
/// aligned.
123123
fn align_buf(buf: &mut [u8]) -> Option<&mut [u8]> {
124-
let addr = buf.as_ptr() as usize;
125-
let offset = Self::offset_up_to_alignment(addr);
124+
let offset = buf.as_ptr().align_offset(Self::alignment());
126125
buf.get_mut(offset..)
127126
}
128127

129128
/// Assert that some storage is correctly aligned for this type
130129
fn assert_aligned(storage: &mut [u8]) {
131130
if !storage.is_empty() {
132131
assert_eq!(
133-
(storage.as_ptr() as usize) % Self::alignment(),
132+
storage.as_ptr().align_offset(Self::alignment()),
134133
0,
135134
"The provided storage is not correctly aligned for this type"
136135
)

0 commit comments

Comments
 (0)