mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 22:18:23 +03:00
Fix undef mask initialization and test undef reads.
This commit is contained in:
+6
-4
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user