From f312112479e0e1ccd8d323a6c79fd78dd357b2fb Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Fri, 4 Oct 2024 15:54:18 -0400 Subject: [PATCH] Fix strict provenance polyfills (#34) * Fix strict provenance polyfills * Make sure we pass Miri without the nightly feature too --- .github/workflows/ci.yml | 4 +++- src/sptr.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ca7f34..4a95e90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,4 +54,6 @@ jobs: rustup override set nightly cargo miri setup - name: Test with Miri - run: cargo miri test --features nightly + run: | + cargo miri test + cargo miri test --features nightly diff --git a/src/sptr.rs b/src/sptr.rs index 8763842..78cb233 100644 --- a/src/sptr.rs +++ b/src/sptr.rs @@ -21,7 +21,7 @@ mod implementation { } pub fn without_provenance_mut(addr: usize) -> *mut T { - addr as _ + unsafe { core::mem::transmute(addr) } } pub fn with_metadata_of(ptr: *const T, meta: *const U) -> *const U { @@ -29,8 +29,8 @@ mod implementation { } pub fn with_metadata_of_mut(ptr: *mut T, mut meta: *const U) -> *mut U { - let meta_ptr = addr_of_mut!(meta).cast::(); - unsafe { meta_ptr.write(ptr.cast::() as usize) } + let meta_ptr = addr_of_mut!(meta).cast::<*mut u8>(); + unsafe { meta_ptr.write(ptr.cast::()) } cast_to_mut(meta) } }