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

Fix (stacked-borrows-)UB found by Miri #121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/byteset/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn inv_memrchr(n1: u8, haystack: &[u8]) -> Option<usize> {
let loop_size = cmp::min(LOOP_SIZE, haystack.len());
let align = USIZE_BYTES - 1;
let start_ptr = haystack.as_ptr();
let end_ptr = haystack[haystack.len()..].as_ptr();
let end_ptr = unsafe { haystack.as_ptr().add(haystack.len()) };
let mut ptr = end_ptr;

unsafe {
Expand Down
7 changes: 2 additions & 5 deletions src/ext_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3063,11 +3063,8 @@ pub trait ByteSlice: Sealed {
// Finally, we are only dealing with u8 data, which is Copy, which
// means we can copy without worrying about ownership/destructors.
unsafe {
ptr::copy(
Copy link
Owner

Choose a reason for hiding this comment

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

Does miri complain here? I can't spot any problem with the existing code.

(Note that I'm aware of stacked borrows and understand the issues here. But that understanding came long after bstr was originally written.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

self.as_bytes().get_unchecked(src_start),
self.as_bytes_mut().get_unchecked_mut(dest),
count,
);
let ptr = self.as_bytes_mut().as_mut_ptr();
ptr::copy(ptr.add(src_start), ptr.add(dest), count);
}
}
}
Expand Down