aboutsummaryrefslogtreecommitdiff
path: root/tests/test_bytes_vec_alloc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_bytes_vec_alloc.rs')
-rw-r--r--tests/test_bytes_vec_alloc.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/test_bytes_vec_alloc.rs b/tests/test_bytes_vec_alloc.rs
index 9d98232..752009f 100644
--- a/tests/test_bytes_vec_alloc.rs
+++ b/tests/test_bytes_vec_alloc.rs
@@ -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>()
+}