use std::error::Error;
use std::fmt;
use rustc::mir::repr as mir;
+use memory::Pointer;
#[derive(Clone, Debug)]
pub enum EvalError {
InvalidBool,
InvalidDiscriminant,
PointerOutOfBounds {
- offset: usize,
+ ptr: Pointer,
size: usize,
- len: usize,
+ allocation_size: usize,
},
ReadPointerAsBytes,
ReadBytesAsPointer,
impl fmt::Display for EvalError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
- EvalError::PointerOutOfBounds { offset, size, len } => write!(f, "pointer offset ({} + {}) outside bounds ({}) of allocation", offset, size, len),
+ EvalError::PointerOutOfBounds { ptr, size, allocation_size } => {
+ write!(f, "memory access of {}..{} outside bounds of allocation {} which has size {}",
+ ptr.offset, ptr.offset + size, ptr.alloc_id, allocation_size)
+ },
_ => write!(f, "{}", self.description()),
}
}
let alloc = self.get(ptr.alloc_id)?;
if ptr.offset + size > alloc.bytes.len() {
return Err(EvalError::PointerOutOfBounds {
- offset: ptr.offset,
+ ptr: ptr,
size: size,
- len: alloc.bytes.len(),
+ allocation_size: alloc.bytes.len(),
});
}
Ok(&alloc.bytes[ptr.offset..ptr.offset + size])
let alloc = self.get_mut(ptr.alloc_id)?;
if ptr.offset + size > alloc.bytes.len() {
return Err(EvalError::PointerOutOfBounds {
- offset: ptr.offset,
+ ptr: ptr,
size: size,
- len: alloc.bytes.len(),
+ allocation_size: alloc.bytes.len(),
});
}
Ok(&mut alloc.bytes[ptr.offset..ptr.offset + size])
#[miri_run]
fn out_of_bounds_read() -> u8 {
let v: Vec<u8> = vec![1, 2];
- unsafe { *v.get_unchecked(5) } //~ ERROR: pointer offset (5 + 1) outside bounds (2) of allocation
+ unsafe { *v.get_unchecked(5) } //~ ERROR: memory access of 5..6 outside bounds of allocation 11 which has size 2
}
#[miri_run]