MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / check_raw_pointer

Function check_raw_pointer

src/utils.rs:43–51  ·  view source on GitHub ↗

Convert a `*mut c_void` to a `*mut T`, checking that it is not null, misaligned, or pointing to a region of memory that wraps around the address space.

(value: *mut c_void)

Source from the content-addressed store, hash-verified

41/// misaligned, or pointing to a region of memory that wraps around the address
42/// space.
43pub(crate) fn check_raw_pointer<T>(value: *mut c_void) -> Option<NonNull<T>> {
44 if (value as usize).checked_add(size_of::<T>()).is_none()
45 || (value as usize) % align_of::<T>() != 0
46 {
47 return None;
48 }
49
50 NonNull::new(value.cast())
51}
52
53/// Create a union value containing a default value in one of its arms.
54///

Callers

nothing calls this directly

Calls 1

checked_addMethod · 0.80

Tested by

no test coverage detected