mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
9b0d4b20ea
commit
7455ff1ea4
@@ -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;
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user