7537b20626
add lint deref_nullptr detecting when a null ptr is dereferenced fixes #83856 changelog: add lint that detect code like ```rust unsafe { &*core::ptr::null::<i32>() }; unsafe { addr_of!(std::ptr::null::<i32>()) }; let x: i32 = unsafe {*core::ptr::null()}; let x: i32 = unsafe {*core::ptr::null_mut()}; unsafe {*(0 as *const i32)}; unsafe {*(core::ptr::null() as *const i32)}; ``` ``` warning: Dereferencing a null pointer causes undefined behavior --> src\main.rs:5:26 | 5 | let x: i32 = unsafe {*core::ptr::null()}; | ^^^^^^^^^^^^^^^^^^ | | | a null pointer is dereferenced | this code causes undefined behavior when executed | = note: `#[warn(deref_nullptr)]` on by default ``` Limitation: It does not detect code like ```rust const ZERO: usize = 0; unsafe {*(ZERO as *const i32)}; ``` or code where `0` is not directly a literal |
||
---|---|---|
.. | ||
nonstandard_style | ||
array_into_iter.rs | ||
builtin.rs | ||
context.rs | ||
early.rs | ||
internal.rs | ||
late.rs | ||
levels.rs | ||
lib.rs | ||
methods.rs | ||
non_ascii_idents.rs | ||
non_fmt_panic.rs | ||
nonstandard_style.rs | ||
noop_method_call.rs | ||
passes.rs | ||
redundant_semicolon.rs | ||
traits.rs | ||
types.rs | ||
unused.rs |