-
Notifications
You must be signed in to change notification settings - Fork 309
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
offset_of! is unsound #1564
Comments
@kazcw what is our alternative? How likely is this to fail in practice? |
If it were just a matter of breaking In this case one option would be: instead of doing the address calculations using a hypothetical instance at NULL, use a real instance. Since this macro is only used with C structs, and Rust has no constraints on the value range of fields in C structs, the example value can be conjured with |
Thank you for the explanation @kazcw that is very helpful. |
Ok, let's try moving to https://github.com/Gilnaa/memoffset. |
In that case I presume we need to replace the usage of |
FWIW, the latest version of https://github.com/Gilnaa/memoffset actually works in a way that is compliant with the Rust Reference. :) But doing |
offset_of! is unsound. There's no right way to implement it until RFC #2582 is implemented. The RFC describes why things like the
ptr::null
trick are invalid:The text was updated successfully, but these errors were encountered: