Skip to content

Commit

Permalink
Derive the &mut T in as_mut from a raw ptr, not &T (#471)
Browse files Browse the repository at this point in the history
The previous implementation converts a &T to a &mut T by casting through
raw pointers, which is UB. Miri can detect this with
-Zmiri-tag-raw-pointers, though the wasmparser crate itself doesn't
have the test coverage to hit it.
  • Loading branch information
saethlin authored Feb 7, 2022
1 parent 5380b16 commit 43860b8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/wasmparser/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ mod arc {
return None;
}
debug_assert!(Arc::get_mut(&mut self.arc).is_some());
Some(unsafe { &mut *(&*self.arc as *const T as *mut T) })
Some(unsafe { &mut *(Arc::as_ptr(&self.arc) as *mut T) })
}

pub fn assert_mut(&mut self) -> &mut T {
Expand Down

0 comments on commit 43860b8

Please sign in to comment.