Made by DeepSource

Found transmute between a literal and a *T ptr RS-E1028

Bug risk

Transmuting a literal to pointer is undefined behavior. For the cases where it is required to construct a null ptr, Rust provides the std::ptr::null() and std::ptr::null_mut() methods instead.


Not all cases can be detected at the moment of this writing. For example, variables which hold a null pointer and are then fed to a transmute call aren't detectable yet.

Bad practice

fn foo() {
    let null_ref: &u64 = unsafe { std::mem::transmute(0 as *const u64) };