Fix undef mask initialization and test undef reads.
This commit is contained in:
parent
cfe36d63e5
commit
284404da06
2 changed files with 13 additions and 4 deletions
|
|
@ -106,7 +106,7 @@ impl Memory {
|
|||
let alloc = Allocation {
|
||||
bytes: vec![0; size].into_boxed_slice(),
|
||||
relocations: BTreeMap::new(),
|
||||
undef_mask: UndefMask::new(),
|
||||
undef_mask: UndefMask::new(size),
|
||||
};
|
||||
self.alloc_map.insert(self.next_id, alloc);
|
||||
self.next_id += 1;
|
||||
|
|
@ -426,11 +426,13 @@ pub struct UndefMask {
|
|||
}
|
||||
|
||||
impl UndefMask {
|
||||
fn new() -> Self {
|
||||
UndefMask {
|
||||
fn new(size: usize) -> Self {
|
||||
let mut m = UndefMask {
|
||||
blocks: vec![],
|
||||
len: 0,
|
||||
}
|
||||
};
|
||||
m.grow(size, false);
|
||||
m
|
||||
}
|
||||
|
||||
/// Check whether the range `start..end` (end-exclusive) is entirely defined.
|
||||
|
|
|
|||
|
|
@ -23,3 +23,10 @@ fn invalid_bools_are_rejected() -> u8 {
|
|||
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
|
||||
if b { 1 } else { 2 }
|
||||
}
|
||||
|
||||
#[miri_run]
|
||||
fn undefined_byte_reads_are_rejected() -> u8 {
|
||||
let v: Vec<u8> = Vec::with_capacity(10);
|
||||
let undef = unsafe { *v.get_unchecked(5) };
|
||||
undef + 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue