diff options
| author | chromatic <chromatic@wgz.org> | 2014-02-17 18:38:23 -0800 | 
|---|---|---|
| committer | chromatic <chromatic@wgz.org> | 2014-02-17 19:35:59 -0800 | 
| commit | 96102b39455d414ec5966cb4547f5317f3cada15 (patch) | |
| tree | 042091b4e01ba00fa86e6588a624f0030cd67a8c | |
| parent | 93a2ee807abafa25555b17b6432d02db53f9e756 (diff) | |
| download | rust-96102b39455d414ec5966cb4547f5317f3cada15.tar.gz rust-96102b39455d414ec5966cb4547f5317f3cada15.zip  | |
Made fail_bounds_check more careful with strings.
Fixes GH #11976.
| -rw-r--r-- | src/libstd/unstable/lang.rs | 14 | 
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libstd/unstable/lang.rs b/src/libstd/unstable/lang.rs index 4648f149a9f..8818cb0d270 100644 --- a/src/libstd/unstable/lang.rs +++ b/src/libstd/unstable/lang.rs @@ -10,7 +10,10 @@ //! Runtime calls emitted by the compiler. -use c_str::ToCStr; +use c_str::CString; +use libc::c_char; +use cast; +use option::Some; #[cold] #[lang="fail_"] @@ -23,7 +26,14 @@ pub fn fail_(expr: *u8, file: *u8, line: uint) -> ! { pub fn fail_bounds_check(file: *u8, line: uint, index: uint, len: uint) -> ! { let msg = format!("index out of bounds: the len is {} but the index is {}", len as uint, index as uint); - msg.with_c_str(|buf| fail_(buf as *u8, file, line)) + + let file_str = match unsafe { CString::new(file as *c_char, false) }.as_str() { + // This transmute is safe because `file` is always stored in rodata. + Some(s) => unsafe { cast::transmute::<&str, &'static str>(s) }, + None => "file wasn't UTF-8 safe" + }; + + ::rt::begin_unwind(msg, file_str, line) } #[lang="malloc"]  | 
