mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
miri: don't use int2ptr casts for invalid pointers (#553)
This commit is contained in:
@@ -45,7 +45,7 @@ impl Ledger {
|
||||
if entry_ptr
|
||||
.compare_exchange(
|
||||
ptr,
|
||||
usize::MAX as *mut u8,
|
||||
invalid_ptr(usize::MAX),
|
||||
Ordering::SeqCst,
|
||||
Ordering::SeqCst,
|
||||
)
|
||||
@@ -103,3 +103,12 @@ fn test_bytes_truncate_and_advance() {
|
||||
bytes.advance(1);
|
||||
drop(bytes);
|
||||
}
|
||||
|
||||
/// Returns a dangling pointer with the given address. This is used to store
|
||||
/// integer data in pointer fields.
|
||||
#[inline]
|
||||
fn invalid_ptr<T>(addr: usize) -> *mut T {
|
||||
let ptr = std::ptr::null_mut::<u8>().wrapping_add(addr);
|
||||
debug_assert_eq!(ptr as usize, addr);
|
||||
ptr.cast::<T>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user