1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // error-pattern:index out of bounds
17 // This should cause a bounds-check failure, but may not if we do our
18 // bounds checking by comparing the scaled index to the vector's
19 // address-bounds, since we've scaled the index to wrap around to the
20 // address of the 0th cell in the array (even though the index is
23 let x = vec!(1u,2u,3u);
25 let base = x.as_ptr() as uint;
26 let idx = base / mem::size_of::<uint>();
27 println!("ov1 base = 0x{:x}", base);
28 println!("ov1 idx = 0x{:x}", idx);
29 println!("ov1 sizeof::<uint>() = 0x{:x}", mem::size_of::<uint>());
30 println!("ov1 idx * sizeof::<uint>() = 0x{:x}",
31 idx * mem::size_of::<uint>());
34 println!("ov1 0x{:x}", x[idx]);