1
Fork 0
rust/src/test/run-fail/str-overrun.rs

19 lines
368 B
Rust
Raw Normal View History

2010-06-23 21:03:09 -07:00
// -*- rust -*-
// error-pattern:bounds check
2010-06-23 21:03:09 -07:00
fn main() {
2011-07-27 14:19:39 +02:00
let s: str = "hello";
let x: int = 0;
assert (s[x] == 0x68 as u8);
// NB: at the moment a string always has a trailing NULL,
// so the largest index value on the string above is 5, not
// 4. Possibly change this.
2010-06-23 21:03:09 -07:00
// Bounds-check failure.
2010-06-23 21:03:09 -07:00
assert (s[x + 6] == 0x0 as u8);
}