Skip to content

Made fail_bounds_check more careful with strings. #12357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/libstd/unstable/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_"]
Expand All @@ -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"]
Expand Down