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

checker: warn when accessing union fields outside unsafe #7869

Merged
merged 1 commit into from
Jan 4, 2021

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Jan 4, 2021

Rust makes reading (and sometimes writing) union fields require unsafe. This pull does so for both.
https://doc.rust-lang.org/reference/items/unions.html#reading-and-writing-union-fields

Reading union fields is memory-unsafe if there is a type that is a pointer/reference field somewhere inside the union, and it can cause weird values if not used carefully - e.g. an enum field can get a value outside its members.

@ntrel ntrel marked this pull request as ready for review January 4, 2021 18:58
@spytheman spytheman merged commit 040b923 into vlang:master Jan 4, 2021
@ntrel ntrel deleted the unsafe-union branch January 5, 2021 10:57
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.

2 participants