make sure miri never switches over an invalid char value
This commit is contained in:
parent
7a9272c8e1
commit
b10fc7a99f
1 changed files with 7 additions and 1 deletions
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue