-
Notifications
You must be signed in to change notification settings - Fork 707
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
Fix "dereferencing a null pointer" in C layout tests #2203
Conversation
Instead of dereferencing a null pointer, create a MaybeUninit from which we can extract well-defined addresses.
be49600
to
a191871
Compare
This looks as though it would close #1651. |
Will also fix: #2204 |
&(*(::#prefix::ptr::null::<#canonical_ident>())).#field_name as *const _ as usize | ||
let uninit = ::#prefix::mem::MaybeUninit::<#canonical_ident>::uninit(); | ||
let ptr = uninit.as_ptr(); | ||
::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using offset_from() might work here (as #field_offset
will be a literal you don't need to worry about usize/isize conversions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offset_from()
assumes that the two pointers have the same type, which is not the case in this case, and if we were to cast to *const u8
, I would rather just directly use usize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If tests are happy, I'm happy. Thanks for this!
It seems just a version bump was required. Looks like this PR: rust-lang/rust-bindgen#2203
Pull in fix for rust-lang/rust-bindgen#2203 and remove allow on null pointer dereference lint.
Was fixed in rust-lang/rust-bindgen#2203 Signed-off-by: mulhern <[email protected]>
bindgen is using addr_of! instead of "reference first and convert to pointer later" since rust-lang/rust-bindgen#2203. Regenerate bindings.rs with bindgen 0.63.0. BUG=b:239850356 TEST=cargo clippy Change-Id: Id4f6f4c0ccbf222de27cd35d42dbdda7958dac2f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/4570362 Commit-Queue: Chih-Yang Hsia <[email protected]> Tested-by: [email protected] <[email protected]> Tested-by: ChromeOS Audio Quick Verifier <[email protected]> Tested-by: Chih-Yang Hsia <[email protected]> Reviewed-by: Li-Yu Yu <[email protected]>
Instead of dereferencing a null pointer, create a
MaybeUninit
from which we can extract well-defined addresses.