From: Scott Olson Date: Wed, 6 Apr 2016 10:35:25 +0000 (-0600) Subject: Fix undef mask initialization and test undef reads. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=284404da06ace69589dfc1a0fa5fb7249607fc89;p=rust.git Fix undef mask initialization and test undef reads. --- diff --git a/src/memory.rs b/src/memory.rs index c8f19fa165f..84cd95409b8 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -106,7 +106,7 @@ pub fn allocate(&mut self, size: usize) -> Pointer { 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. diff --git a/test/errors.rs b/test/errors.rs index 8d66ec48ad1..c6e6e16b889 100755 --- a/test/errors.rs +++ b/test/errors.rs @@ -23,3 +23,10 @@ fn invalid_bools_are_rejected() -> u8 { let b = unsafe { std::mem::transmute::(2) }; if b { 1 } else { 2 } } + +#[miri_run] +fn undefined_byte_reads_are_rejected() -> u8 { + let v: Vec = Vec::with_capacity(10); + let undef = unsafe { *v.get_unchecked(5) }; + undef + 1 +}