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
}
Metadata
Metadata
Assignees
Labels
Area: Documentation for any part of the project, including the compiler, standard library, and toolsCategory: This is a bug.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.Relevant to the spec team.