preemptively change some assertions into errors

上级 2f81729e
......@@ -1224,9 +1224,12 @@ fn write_primval(
}
Lvalue::Global(cid) => {
let global_val = self.globals.get_mut(&cid).expect("global not cached");
assert!(global_val.mutable);
global_val.data = Some(Value::ByVal(val));
Ok(())
if global_val.mutable {
global_val.data = Some(Value::ByVal(val));
Ok(())
} else {
Err(EvalError::ModifiedConstantMemory)
}
}
}
}
......@@ -1240,7 +1243,9 @@ fn write_value(
match dest {
Lvalue::Global(cid) => {
let dest = *self.globals.get_mut(&cid).expect("global should be cached");
assert!(dest.mutable);
if !dest.mutable {
return Err(EvalError::ModifiedConstantMemory);
}
self.write_value_possibly_by_val(
src_val,
|this, val| *this.globals.get_mut(&cid).expect("already checked") = Global { data: Some(val), ..dest },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册