Skip to content

Commit dc54f1d

Browse files
committed
miri_print_borrow_state: show error when AllocId is invalid
1 parent 21f9175 commit dc54f1d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/tools/miri/src/shims/foreign_items.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
289289
let [id, show_unnamed] = this.check_shim(abi, Abi::Rust, link_name, args)?;
290290
let id = this.read_scalar(id)?.to_u64()?;
291291
let show_unnamed = this.read_scalar(show_unnamed)?.to_bool()?;
292-
if let Some(id) = std::num::NonZero::new(id) {
293-
this.print_borrow_state(AllocId(id), show_unnamed)?;
292+
if let Some(id) = std::num::NonZero::new(id).map(AllocId)
293+
&& this.get_alloc_info(id).2 == AllocKind::LiveData
294+
{
295+
this.print_borrow_state(id, show_unnamed)?;
296+
} else {
297+
eprintln!("{id} is not the ID of a live data allocation");
294298
}
295299
}
296300
"miri_pointer_name" => {

0 commit comments

Comments
 (0)