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