Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Working With Uninitialized Memory" makes overly broad claims #435

Open
RalfJung opened this issue Dec 12, 2023 · 0 comments
Open

"Working With Uninitialized Memory" makes overly broad claims #435

RalfJung opened this issue Dec 12, 2023 · 0 comments

Comments

@RalfJung
Copy link
Member

Here, the Nomicon claims

All runtime-allocated memory in a Rust program begins its life as uninitialized. In this state the value of the memory is an indeterminate pile of bits that may or may not even reflect a valid state for the type that is supposed to inhabit that location of memory. Attempting to interpret this memory as a value of any type will cause Undefined Behavior.

That's not true; there are types that allow reading a value from uninitialized memory for some or all of their bytes: MaybeUninit is the obvious example, and more generally unions with a () field (or even all unions, details are TBD). Also, padding bytes are allowed to be uninitialized.

@RalfJung RalfJung changed the title "Working With Uninitialized Memory" makes voerly broad claims "Working With Uninitialized Memory" makes overly broad claims Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant