Skip to content

Commit

Permalink
make sure miri never switches over an invalid char value
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jun 21, 2016
1 parent 7a9272c commit b10fc7a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,17 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {

SwitchInt { ref discr, ref values, ref targets, .. } => {
let discr_ptr = self.eval_lvalue(discr)?.to_ptr();
let discr_ty = self.lvalue_ty(discr);
let discr_size = self
.type_layout(self.lvalue_ty(discr))
.type_layout(discr_ty)
.size(&self.tcx.data_layout)
.bytes() as usize;
let discr_val = self.memory.read_uint(discr_ptr, discr_size)?;
if let ty::TyChar = discr_ty.sty {
if ::std::char::from_u32(discr_val as u32).is_none() {
return Err(EvalError::InvalidChar(discr_val as u32));
}
}

// Branch to the `otherwise` case by default, if no match is found.
let mut target_block = targets[targets.len() - 1];
Expand Down

0 comments on commit b10fc7a

Please sign in to comment.