-
Notifications
You must be signed in to change notification settings - Fork 288
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
cast the entire slice to a raw pointer, not just the first element #80
Conversation
@@ -357,7 +357,8 @@ impl<T> RawTable<T> { | |||
pub fn new() -> Self { | |||
Self { | |||
data: NonNull::dangling(), | |||
ctrl: NonNull::from(&Group::static_empty()[0]), | |||
// Be careful to cast the entire slice to a raw pointer. | |||
ctrl: unsafe { NonNull::new_unchecked(Group::static_empty().as_ptr() as *mut u8) }, |
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.
Btw, the mut
cast here is actually meaningful -- the rest of the code must be careful not to write to this! But I suppose that's already the case, this is a shared global static after all.
@bors r+ |
📌 Commit 2693d12 has been approved by |
cast the entire slice to a raw pointer, not just the first element A strict reading of pointer provenance implies that when a `&T` gets cast to `*const T`, you may only use the raw pointer to access that `T`, not its neighbors. That's what Miri currently implements, though it is less strict around statics (which is why this one does not currently cause a Miri failure -- I'd like to make Miri more strict though). Cc rust-lang/unsafe-code-guidelines#134
☀️ Test successful - checks-travis |
What is needed to get this updated in rustc? |
I need to publish a new version of the crate and Cargo.lock needs to be updated in rustc. |
I published v0.3.1 with this change. |
Thanks a lot! |
bump hashbrown Bump hashbrown to a version that includes rust-lang/hashbrown#80.
Bump hashbrown to 0.4.0 Fixes #61357 This also includes rust-lang/hashbrown#80.
A strict reading of pointer provenance implies that when a
&T
gets cast to*const T
, you may only use the raw pointer to access thatT
, not its neighbors. That's what Miri currently implements, though it is less strict around statics (which is why this one does not currently cause a Miri failure -- I'd like to make Miri more strict though).Cc rust-lang/unsafe-code-guidelines#134