From 330f2fda1cb1cd3befee342299e5f7ab31a85892 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 1 Jul 2026 10:55:57 +0100 Subject: [PATCH] arch: mptable: Avoid unsafe slice::from_raw_parts() The struct already implements ByteValued so this unsafe block can be changed to call as_slice() from that trait. Signed-off-by: Rob Bradford --- arch/src/x86_64/mptable.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/src/x86_64/mptable.rs b/arch/src/x86_64/mptable.rs index 041503f70..cc9865240 100644 --- a/arch/src/x86_64/mptable.rs +++ b/arch/src/x86_64/mptable.rs @@ -5,7 +5,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-BSD-3-Clause file. -use std::{result, slice}; +use std::result; use libc::c_uchar; use log::{info, warn}; @@ -101,11 +101,8 @@ const CPU_FEATURE_APIC: u32 = 0x200; const CPU_FEATURE_FPU: u32 = 0x001; fn compute_checksum(v: &T) -> u8 { - let v: *const T = v; - // SAFETY: we are only reading the bytes within the size of the `T` reference `v`. - let v_slice = unsafe { slice::from_raw_parts(v.cast(), size_of::()) }; let mut checksum: u8 = 0; - for i in v_slice.iter() { + for i in v.as_slice().iter() { checksum = checksum.wrapping_add(*i); } checksum