mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-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
8b101fb890
commit
ae7113e1d4
@@ -233,7 +233,7 @@ impl VirtioDevice for Blk {
|
||||
fn write_config(&mut self, offset: u64, data: &[u8]) {
|
||||
// The "writeback" field is the only mutable field
|
||||
let writeback_offset =
|
||||
(&self.config.writeback as *const _ as u64) - (&self.config as *const _ as u64);
|
||||
(&raw const self.config.writeback as u64) - (&raw const self.config as u64);
|
||||
if offset != writeback_offset || data.len() != std::mem::size_of_val(&self.config.writeback)
|
||||
{
|
||||
error!(
|
||||
|
||||
@@ -687,7 +687,7 @@ impl VhostUserHandle {
|
||||
// SAFETY: region is of size len
|
||||
let bitmap: &[u64] = unsafe {
|
||||
// Cast the pointer to u64
|
||||
let ptr = region.as_ptr() as *const u64;
|
||||
let ptr = region.as_ptr().cast();
|
||||
std::slice::from_raw_parts(ptr, len)
|
||||
};
|
||||
Ok(MemoryRangeTable::from_dirty_bitmap(
|
||||
|
||||
Reference in New Issue
Block a user