From 420b4260b4000af2b1ffb579fb7df5e437e0faa2 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 14 Oct 2013 22:43:03 -0400 Subject: [PATCH] fix bounds checking failure message casting the `uint` to an `int` can result in printing high values as negative intege --- src/libstd/unstable/lang.rs | 2 +- src/test/run-fail/small-negative-indexing.rs | 19 ------------------ src/test/run-fail/vec-underrun.rs | 21 -------------------- 3 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 src/test/run-fail/small-negative-indexing.rs delete mode 100644 src/test/run-fail/vec-underrun.rs diff --git a/src/libstd/unstable/lang.rs b/src/libstd/unstable/lang.rs index 6f2928e99fe..e30d0e77367 100644 --- a/src/libstd/unstable/lang.rs +++ b/src/libstd/unstable/lang.rs @@ -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); } diff --git a/src/test/run-fail/small-negative-indexing.rs b/src/test/run-fail/small-negative-indexing.rs deleted file mode 100644 index a016af24451..00000000000 --- a/src/test/run-fail/small-negative-indexing.rs +++ /dev/null @@ -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 or the MIT license -// , 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]); -} diff --git a/src/test/run-fail/vec-underrun.rs b/src/test/run-fail/vec-underrun.rs deleted file mode 100644 index 99ce79b3b6c..00000000000 --- a/src/test/run-fail/vec-underrun.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -}