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:
Julian Schindel
2026-04-29 21:55:06 +02:00
committed by Rob Bradford
parent 6de472f1bb
commit 2a6b746f5e
2 changed files with 3 additions and 3 deletions

View File

@@ -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);

View File

@@ -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),
)
};