Skip to content

Commit aad5fde

Browse files
committed
fix deallocating/reallocating with integer pointers
1 parent 802dcb7 commit aad5fde

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/shims/foreign_items.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5050
) -> InterpResult<'tcx> {
5151
let this = self.eval_context_mut();
5252
if !ptr.is_null_ptr(this) {
53+
let ptr = this.force_ptr(ptr)?;
5354
this.memory_mut().deallocate(
54-
ptr.to_ptr()?,
55+
ptr,
5556
None,
5657
MiriMemoryKind::C.into(),
5758
)?;
@@ -78,7 +79,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7879
Ok(Scalar::Ptr(new_ptr))
7980
}
8081
} else {
81-
let old_ptr = old_ptr.to_ptr()?;
82+
let old_ptr = this.force_ptr(old_ptr)?;
8283
let memory = this.memory_mut();
8384
let old_size = Size::from_bytes(memory.get(old_ptr.alloc_id)?.bytes.len() as u64);
8485
if new_size == 0 {
@@ -234,7 +235,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
234235
this.write_scalar(Scalar::Ptr(ptr), dest)?;
235236
}
236237
"__rust_dealloc" => {
237-
let ptr = this.read_scalar(args[0])?.to_ptr()?;
238+
let ptr = this.read_scalar(args[0])?.not_undef()?;
238239
let old_size = this.read_scalar(args[1])?.to_usize(this)?;
239240
let align = this.read_scalar(args[2])?.to_usize(this)?;
240241
if old_size == 0 {
@@ -243,6 +244,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
243244
if !align.is_power_of_two() {
244245
return err!(HeapAllocNonPowerOfTwoAlignment(align));
245246
}
247+
let ptr = this.force_ptr(ptr)?;
246248
this.memory_mut().deallocate(
247249
ptr,
248250
Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())),

0 commit comments

Comments
 (0)