From 3281e621885e45f0b253acb257a22f12d0623fe8 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Sun, 17 Feb 2019 12:58:48 +0100 Subject: [PATCH 1/2] Remove UB in test_is_null test --- src/libcore/tests/ptr.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 2c53e4832a8cc..707519e6734a5 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -40,18 +40,17 @@ fn test() { } #[test] -#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic fn test_is_null() { let p: *const isize = null(); assert!(p.is_null()); - let q = unsafe { p.offset(1) }; + let q = p.wrapping_offset(1); assert!(!q.is_null()); let mp: *mut isize = null_mut(); assert!(mp.is_null()); - let mq = unsafe { mp.offset(1) }; + let mq = mp.wrapping_offset(1); assert!(!mq.is_null()); // Pointers to unsized types -- slices From 0cf1a912e37e6b3be747deb18a521c1d3657afc0 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Sun, 17 Feb 2019 13:04:48 +0100 Subject: [PATCH 2/2] Remove UB in test_ptr_subtraction test --- src/libcore/tests/ptr.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 707519e6734a5..03fe1fe5a7cf8 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -207,7 +207,6 @@ fn test_ptr_addition() { } #[test] -#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic fn test_ptr_subtraction() { unsafe { let xs = vec![0,1,2,3,4,5,6,7,8,9]; @@ -223,8 +222,11 @@ fn test_ptr_subtraction() { let m_start = xs_mut.as_mut_ptr(); let mut m_ptr = m_start.offset(9); - while m_ptr >= m_start { + loop { *m_ptr += *m_ptr; + if m_ptr == m_start { + break; + } m_ptr = m_ptr.offset(-1); }