about summary refs log tree commit diff
path: root/src/libcore/rt.rs
diff options
context:
space:
mode:
authorGareth Daniel Smith <garethdanielsmith@gmail.com>2012-09-29 12:34:11 +0100
committerBrian Anderson <banderson@mozilla.com>2012-09-30 14:55:56 -0700
commit1c76d189c02ddc6cb6fcf15ae94f3a3ae4de5fa7 (patch)
tree064a5a635790111611b04e678e1c1db90ce00426 /src/libcore/rt.rs
parent2f95f7d8de29baca271d04ef89021146061ce975 (diff)
downloadrust-1c76d189c02ddc6cb6fcf15ae94f3a3ae4de5fa7.tar.gz
rust-1c76d189c02ddc6cb6fcf15ae94f3a3ae4de5fa7.zip
When a vec/str bounds check fails, include the bad index and the length of the str/vec in the fail message.
Diffstat (limited to 'src/libcore/rt.rs')
-rw-r--r--src/libcore/rt.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs
index 644edb69d56..da598fc3e7f 100644
--- a/src/libcore/rt.rs
+++ b/src/libcore/rt.rs
@@ -40,6 +40,16 @@ fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) {
     rustrt::rust_upcall_fail(expr, file, line);
 }
 
+#[rt(fail_bounds_check)]
+fn rt_fail_bounds_check(file: *c_char, line: size_t,
+                        index: size_t, len: size_t) {
+    let msg = fmt!("index out of bounds: the len is %d but the index is %d",
+                    len as int, index as int);
+    do str::as_buf(msg) |p, _len| {
+        rt_fail_(p as *c_char, file, line);
+    }
+}
+
 #[rt(exchange_malloc)]
 fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
     return rustrt::rust_upcall_exchange_malloc(td, size);