1 // error-pattern:index out of bounds
7 // This should cause a bounds-check panic, but may not if we do our
8 // bounds checking by comparing the scaled index to the vector's
9 // address-bounds, since we've scaled the index to wrap around to the
10 // address of the 0th cell in the array (even though the index is
13 let x = vec![1_usize, 2_usize, 3_usize];
15 let base = x.as_ptr() as usize;
16 let idx = base / mem::size_of::<usize>();
17 println!("ov1 base = 0x{:x}", base);
18 println!("ov1 idx = 0x{:x}", idx);
19 println!("ov1 sizeof::<usize>() = 0x{:x}", mem::size_of::<usize>());
20 println!("ov1 idx * sizeof::<usize>() = 0x{:x}",
21 idx * mem::size_of::<usize>());
24 println!("ov1 0x{:x}", x[idx]);