From 4419c9d6aef9c135156ed717dd699c3cec0be397 Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Sun, 10 Mar 2024 06:33:38 -0700 Subject: [PATCH] Fix UB in test_ref_as_expected Summary: From https://github.com/facebookincubator/gazebo/pull/13. Fix up some UB in a test. Reviewed By: dtolnay Differential Revision: D54718707 fbshipit-source-id: 52169c051bc5efd399d0e92f1438e97e7a3d2833 --- gazebo/gazebo/src/cell.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gazebo/gazebo/src/cell.rs b/gazebo/gazebo/src/cell.rs index 8b09b39ad..a55a56f42 100644 --- a/gazebo/gazebo/src/cell.rs +++ b/gazebo/gazebo/src/cell.rs @@ -212,7 +212,6 @@ mod tests { use std::mem; use super::*; - use crate::cast; #[test] fn test_from_ref_docs() { @@ -276,11 +275,11 @@ mod tests { let orig = RefCell::new("test".to_owned()); let p = orig.borrow(); let p2 = Ref::clone(&p); - let (pointer, cell): (usize, usize) = unsafe { mem::transmute(p) }; + let (pointer, cell): (*const String, *const ()) = unsafe { mem::transmute(p) }; // We expect the first to be a pointer to the underlying string - assert_eq!(pointer, cast::ptr_to_usize(Ref::deref(&p2))); + assert_eq!(pointer, Ref::deref(&p2) as *const String); // We want to make sure the second is never zero - assert_ne!(cell, 0); + assert!(!cell.is_null()); // Put it back as it was, to make sure our test doesn't leak memory let _ignore: Ref = unsafe { mem::transmute((pointer, cell)) };