Skip to content

Commit 4f659ed

Browse files
committed
fix for infallible allocation
1 parent fd12f95 commit 4f659ed

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/fn_call.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
8484
this.write_null(dest)?;
8585
} else {
8686
let align = this.tcx.data_layout.pointer_align.abi;
87-
let ptr = this.memory_mut().allocate(Size::from_bytes(size), align, MiriMemoryKind::C.into())?;
87+
let ptr = this.memory_mut().allocate(Size::from_bytes(size), align, MiriMemoryKind::C.into());
8888
this.write_scalar(Scalar::Ptr(ptr.with_default_tag()), dest)?;
8989
}
9090
}
@@ -114,7 +114,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
114114
Size::from_bytes(size),
115115
Align::from_bytes(align).unwrap(),
116116
MiriMemoryKind::Rust.into()
117-
)?
117+
)
118118
.with_default_tag();
119119
this.write_scalar(Scalar::Ptr(ptr), dest)?;
120120
}
@@ -132,7 +132,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
132132
Size::from_bytes(size),
133133
Align::from_bytes(align).unwrap(),
134134
MiriMemoryKind::Rust.into()
135-
)?
135+
)
136136
.with_default_tag();
137137
this.memory_mut()
138138
.get_mut(ptr.alloc_id)?
@@ -358,7 +358,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
358358
Size::from_bytes((value.len() + 1) as u64),
359359
Align::from_bytes(1).unwrap(),
360360
MiriMemoryKind::Env.into(),
361-
)?.with_default_tag();
361+
).with_default_tag();
362362
{
363363
let alloc = this.memory_mut().get_mut(value_copy.alloc_id)?;
364364
alloc.write_bytes(tcx, value_copy, &value)?;

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
101101

102102
// Return value (in static memory so that it does not count as leak)
103103
let ret = ecx.layout_of(start_mir.return_ty())?;
104-
let ret_ptr = ecx.allocate(ret, MiriMemoryKind::MutStatic.into())?;
104+
let ret_ptr = ecx.allocate(ret, MiriMemoryKind::MutStatic.into());
105105

106106
// Push our stack frame
107107
ecx.push_stack_frame(
@@ -125,7 +125,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
125125
ecx.write_scalar(argc, dest)?;
126126
// Store argc for macOS _NSGetArgc
127127
{
128-
let argc_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into())?;
128+
let argc_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into());
129129
ecx.write_scalar(argc, argc_place.into())?;
130130
ecx.machine.argc = Some(argc_place.ptr.to_ptr()?);
131131
}
@@ -136,14 +136,14 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
136136
let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
137137
let cmd = ecx.memory_mut().allocate_static_bytes(CMD.as_bytes()).with_default_tag();
138138
let raw_str_layout = ecx.layout_of(ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8))?;
139-
let cmd_place = ecx.allocate(raw_str_layout, MiriMemoryKind::Env.into())?;
139+
let cmd_place = ecx.allocate(raw_str_layout, MiriMemoryKind::Env.into());
140140
ecx.write_scalar(Scalar::Ptr(cmd), cmd_place.into())?;
141141
ecx.memory_mut().mark_immutable(cmd_place.to_ptr()?.alloc_id)?;
142142
// Store argv for macOS _NSGetArgv
143143
{
144144
let argv = cmd_place.ptr;
145145
ecx.write_scalar(argv, dest)?;
146-
let argv_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into())?;
146+
let argv_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into());
147147
ecx.write_scalar(argv, argv_place.into())?;
148148
ecx.machine.argv = Some(argv_place.ptr.to_ptr()?);
149149
}
@@ -155,7 +155,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
155155
Size::from_bytes(cmd_utf16.len() as u64 * 2),
156156
Align::from_bytes(2).unwrap(),
157157
MiriMemoryKind::Env.into(),
158-
)?.with_default_tag();
158+
).with_default_tag();
159159
ecx.machine.cmd_line = Some(cmd_ptr);
160160
// store the UTF-16 string
161161
let char_size = Size::from_bytes(2);
@@ -516,13 +516,13 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
516516
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
517517
ptr: Pointer,
518518
kind: MemoryKind<Self::MemoryKinds>,
519-
) -> EvalResult<'tcx, Pointer<Borrow>> {
519+
) -> Pointer<Borrow> {
520520
if !ecx.machine.validate {
521521
// No tracking
522-
Ok(ptr.with_default_tag())
522+
ptr.with_default_tag()
523523
} else {
524524
let tag = ecx.tag_new_allocation(ptr.alloc_id, kind);
525-
Ok(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
525+
Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag)
526526
}
527527
}
528528

0 commit comments

Comments
 (0)