-
Notifications
You must be signed in to change notification settings - Fork 352
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
uninitialized bytes in a local variable are not caught #2732
Comments
I get the same result if I make |
The type of Writing this code is a very bad idea, but it isn't UB. Miri is correctly quiet here. The docs for
And in this code, I think Ralf would say you didn't "use"
And you do none of those things to |
Yeah I didn't mean to imply that the second copy should be UB, and maybe it's a red herring that I should've left out. (It's an artifact of the original example that prompted this question.) Maybe this is a better, more minimal example: struct Foo {
_a: u8,
_b: u16,
}
fn main() {
let mut x = 0u64;
unsafe {
std::ptr::copy_nonoverlapping(
&Foo { _a: 1, _b: 2 } as *const Foo as *const u8,
&mut x as *mut u64 as *mut u8,
4,
);
}
// x is partially uninitialized
} |
Yes, exactly the same logic applies here. You do not do anything with |
This question is not entirely settled, see rust-lang/unsafe-code-guidelines#84. However making code like yours UB will require a lot of extra complexity and the benefit of that is unclear.
|
Good to know! |
Playground link
This is similar to #2518 (uninitialized value behind a reference), except here the uninitialized value is in a local variable.
Is it expected that Miri doesn't currently trigger on this code? Any thoughts about whether this is likely to be UB in the future?
The text was updated successfully, but these errors were encountered: