block: 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 7455ff1ea4
commit 2b6e9df4e3
8 changed files with 37 additions and 47 deletions

View File

@@ -931,8 +931,7 @@ mod unit_tests {
unsafe { ptr::write_bytes(buf, 0xAB, alignment) };
// SAFETY: buf is aligned and sized for O_DIRECT; fd is valid.
let written =
unsafe { libc::pwrite(f.as_raw_fd(), buf as *const libc::c_void, alignment, 0) };
let written = unsafe { libc::pwrite(f.as_raw_fd(), buf.cast(), alignment, 0) };
assert_eq!(
written as usize,
alignment,
@@ -943,7 +942,7 @@ mod unit_tests {
// SAFETY: buf is valid for `alignment` bytes.
unsafe { ptr::write_bytes(buf, 0x00, alignment) };
// SAFETY: buf is aligned and sized for O_DIRECT; fd is valid.
let read = unsafe { libc::pread(f.as_raw_fd(), buf as *mut libc::c_void, alignment, 0) };
let read = unsafe { libc::pread(f.as_raw_fd(), buf.cast(), alignment, 0) };
assert_eq!(
read as usize,
alignment,