Skip to content

Commit

Permalink
Fix UB in test_ref_as_expected
Browse files Browse the repository at this point in the history
Summary: From facebookincubator/gazebo#13. Fix up some UB in a test.

Reviewed By: dtolnay

Differential Revision: D54718707

fbshipit-source-id: 52169c051bc5efd399d0e92f1438e97e7a3d2833
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Mar 10, 2024
1 parent a16cc26 commit 4419c9d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions gazebo/gazebo/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ mod tests {
use std::mem;

use super::*;
use crate::cast;

#[test]
fn test_from_ref_docs() {
Expand Down Expand Up @@ -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<String> = unsafe { mem::transmute((pointer, cell)) };
Expand Down

0 comments on commit 4419c9d

Please sign in to comment.