misc: 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 c97d635d40
commit 032f29da29
2 changed files with 9 additions and 8 deletions

View File

@@ -84,7 +84,7 @@ pub fn drain_completions(async_io: &mut dyn AsyncIo, count: usize) {
/// Build an iovec suitable for a read into `buf`.
pub fn read_iovec(buf: &mut [u8]) -> libc::iovec {
libc::iovec {
iov_base: buf.as_mut_ptr() as *mut libc::c_void,
iov_base: buf.as_mut_ptr().cast(),
iov_len: buf.len(),
}
}
@@ -92,7 +92,7 @@ pub fn read_iovec(buf: &mut [u8]) -> libc::iovec {
/// Build an iovec suitable for a write from `buf`.
pub fn write_iovec(buf: &[u8]) -> libc::iovec {
libc::iovec {
iov_base: buf.as_ptr() as *mut libc::c_void,
iov_base: buf.as_ptr().cast::<libc::c_void>().cast_mut(),
iov_len: buf.len(),
}
}