Skip to content

Commit

Permalink
Merge pull request #72 from jrose-signal/windows-pointer-provenance-fix
Browse files Browse the repository at this point in the history
Windows: Prevent pointer provenance "optimization"
  • Loading branch information
dtolnay authored Oct 6, 2023
2 parents 35bc184 + a0287cb commit c0ff555
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/distributed_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ impl<T> DistributedSlice<[T]> {
// using the unsafe `private_new`.
None => unsafe { hint::unreachable_unchecked() },
};

// On Windows, make sure we discard provenance information.
// Otherwise, the compiler has enough information to see we are going "out of bounds".
#[cfg(target_os = "windows")]
let start = core::hint::black_box(start);

unsafe { slice::from_raw_parts(start, len) }
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/distributed_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ fn test_elided_lifetime() {
static ELEMENT: &str = "...";

assert!(!MYSLICE.is_empty());
assert_eq!(MYSLICE[0], "...");
}

0 comments on commit c0ff555

Please sign in to comment.