From e82e6132ecb4c1c789a6e41e61aba551bb6003df Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 21 Oct 2016 11:51:24 +0200 Subject: [PATCH] preemptively change some assertions into errors --- src/interpreter/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index bcab8be53e9..66053e9dd59 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -1224,9 +1224,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { } 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 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { 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 },