devices: replace as <pointer> casts with safer alternatives

`as` casts can change mutability, which quickly leads to undefined
behavior.

Signed-off-by: Julian Schindel <mail@arctic-alpaca.de>
This commit is contained in:
Julian Schindel
2026-04-29 21:55:06 +02:00
committed by Rob Bradford
parent 9b0d4b20ea
commit 7455ff1ea4
2 changed files with 3 additions and 3 deletions

View File

@@ -122,13 +122,13 @@ impl BusDevice for Cmos {
// the tm and timespec struct because it contains only plain data.
let update_in_progress = unsafe {
let mut timespec: timespec = mem::zeroed();
clock_gettime(CLOCK_REALTIME, &mut timespec as *mut _);
clock_gettime(CLOCK_REALTIME, &raw mut timespec);
// https://github.com/rust-lang/libc/issues/1848
#[cfg_attr(target_env = "musl", allow(deprecated))]
let now: time_t = timespec.tv_sec;
let mut tm: tm = mem::zeroed();
gmtime_r(&now, &mut tm as *mut _);
gmtime_r(&now, &raw mut tm);
// The following lines of code are safe but depend on tm being in scope.
seconds = tm.tm_sec;

View File

@@ -443,7 +443,7 @@ impl PvmemcontrolBusDevice {
)));
};
assert!(slice.len() >= range_len);
let res = f(slice.ptr_guard_mut().as_ptr() as _, slice.len());
let res = f(slice.ptr_guard_mut().as_ptr().cast(), slice.len());
if res != 0 {
return Err(Error::LibcFail(io::Error::last_os_error()));
}