mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
net_util: 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
6de472f1bb
commit
2a6b746f5e
@@ -81,7 +81,7 @@ impl TxVirtio {
|
||||
assert!(buf.len() >= desc.len() as usize);
|
||||
let buf = buf.ptr_guard_mut();
|
||||
let iovec = libc::iovec {
|
||||
iov_base: buf.as_ptr() as *mut libc::c_void,
|
||||
iov_base: buf.as_ptr().cast(),
|
||||
iov_len: desc.len() as libc::size_t,
|
||||
};
|
||||
iovecs.push(iovec);
|
||||
@@ -238,7 +238,7 @@ impl RxVirtio {
|
||||
assert!(buf.len() >= desc.len() as usize);
|
||||
let buf = buf.ptr_guard_mut();
|
||||
let iovec = libc::iovec {
|
||||
iov_base: buf.as_ptr() as *mut libc::c_void,
|
||||
iov_base: buf.as_ptr().cast(),
|
||||
iov_len: desc.len() as libc::size_t,
|
||||
};
|
||||
iovecs.push(iovec);
|
||||
|
||||
@@ -169,7 +169,7 @@ impl Tap {
|
||||
// Open calls are safe because we give a constant null-terminated
|
||||
// string and verify the result.
|
||||
libc::open(
|
||||
c"/dev/net/tun".as_ptr() as *const c_char,
|
||||
c"/dev/net/tun".as_ptr().cast(),
|
||||
flags.unwrap_or(libc::O_RDWR | libc::O_NONBLOCK | libc::O_CLOEXEC),
|
||||
)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user