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

Clarify initialized union may contain uninited bytes #1388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hehaoqian
Copy link
Contributor

@hehaoqian hehaoqian commented Aug 3, 2023

New to Rust, just realized this after resolving an issue related to this.

This can be verified by sample code: Rust Playground

Each execution gives different output

#[repr(C)]
union Foo {
    int32: i32,
    int64: i64,
}
unsafe {
    let foo = Foo { int32: 1 };
    // Low 4 bytes are initialized,
    // but high 4 bytes are not.
    println!("{}", foo.int64);
}

@hehaoqian hehaoqian force-pushed the united-bytes-in-union branch 3 times, most recently from 58d110a to 301c299 Compare August 3, 2023 13:41
@hehaoqian hehaoqian changed the title Clarify initialized union may contain united bytes Clarify initialized union may contain uninited bytes Aug 3, 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

Successfully merging this pull request may close these issues.

None yet

1 participant