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

Use ptr::slice_from_raw_parts to fix UB in Miri #54

Closed
wants to merge 1 commit into from

Conversation

clubby789
Copy link

Closes #52 by using ptr::slice_from_raw_parts instead of creating a raw slice and casting to a pointer

bors added a commit to rust-lang/rust-clippy that referenced this pull request Aug 29, 2022
New lint: Raw slice pointer cast

Adds a lint to check for a raw slice being created and cast back to a pointer, suggesting `ptr::slice_from_raw_parts`, to identify UB such as thomcc/rust-typed-arena#54.
```
changelog: [`cast_slice_from_raw_parts`]: Add lint to check for `slice::from_raw_parts(.., ..) as *const _`
```
let start = chunks.current.as_mut_ptr().offset(next_item_index as isize);
let start_uninit = start as *mut MaybeUninit<T>;
slice::from_raw_parts_mut(start_uninit, len) as *mut _
std::ptr::slice_from_raw_parts_mut(start_uninit, len)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not use std directly, since this crate supports no_std.

@thomcc thomcc mentioned this pull request Jan 9, 2023
@thomcc thomcc closed this in 80d469e Jan 9, 2023
@clubby789 clubby789 deleted the miri-fix branch January 9, 2023 20: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.

Miri reports an undefined behavior error
2 participants