fix bounds checking failure message
casting the `uint` to an `int` can result in printing high values as negative intege
This commit is contained in:
parent
a7e8957c59
commit
420b4260b4
@ -25,7 +25,7 @@ pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
|
||||
pub fn fail_bounds_check(file: *c_char, line: size_t,
|
||||
index: size_t, len: size_t) {
|
||||
let msg = format!("index out of bounds: the len is {} but the index is {}",
|
||||
len as int, index as int);
|
||||
len as uint, index as uint);
|
||||
do msg.with_c_str |buf| {
|
||||
fail_(buf, file, line);
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:index out of bounds: the len is 1024 but the index is -1
|
||||
|
||||
use std::vec;
|
||||
|
||||
fn main() {
|
||||
let v = vec::from_fn(1024u, {|n| n});
|
||||
// this should trip a bounds check
|
||||
error2!("{:?}", v[-1i8]);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// -*- rust -*-
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
// error-pattern:index out of bounds: the len is 2 but the index is -1
|
||||
fn main() {
|
||||
let v: ~[int] = ~[10, 20];
|
||||
let x: int = 0;
|
||||
assert_eq!(v[x], 10);
|
||||
// Bounds-check failure.
|
||||
|
||||
assert_eq!(v[x - 1], 20);
|
||||
}
|
Loading…
Reference in New Issue
Block a user