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

Borrowing packed fields is unsafe #109

Open
armaniferrante opened this issue Oct 5, 2021 · 0 comments
Open

Borrowing packed fields is unsafe #109

armaniferrante opened this issue Oct 5, 2021 · 0 comments

Comments

@armaniferrante
Copy link

armaniferrante commented Oct 5, 2021

Compiling with anchor build gives the following warning that should be eliminated.

warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
   --> programs/exchange/src/account.rs:275:56
    |
275 | #[derive(PartialEq, Default, Debug, AnchorDeserialize, AnchorSerialize)]
    |                                                        ^^^^^^^^^^^^^^^
    |
    = note: `#[warn(safe_packed_borrows)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
    = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
    = note: this warning originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

Zero copy uses #[repr(packed)]. Instead of borrowing, you can make a copy of the field.

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