Rust

Rust

Made by DeepSource

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

Bug risk
Major

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.

Note:

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