Open
Description
Pointers to external statics are incorrectly assumed to be non-null and well-aligned. Edition 2024 marking extern
as unsafe does help, but there is no documentation mentioning this, and this still works in 2021 despite forbidding unsafe_code
.
#![forbid(unsafe_code)]
extern "C" {
static mut GLIBC_PRIVATE: u8;
static perror: u64;
}
fn main() {
let x = std::ptr::NonNull::new(&raw mut GLIBC_PRIVATE).unwrap();
println!("{x:?}"); // 0x0
let y = &raw const perror;
println!("{y:?} {}", y.is_aligned()); // 0x7c5aa9e5ea93 true
}