Skip to content

Commit

Permalink
Made fail_bounds_check more careful with strings.
Browse files Browse the repository at this point in the history
Fixes GH #11976.
  • Loading branch information
chromatic committed Feb 18, 2014
1 parent 93a2ee8 commit 96102b3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/libstd/unstable/lang.rs
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

5 comments on commit 96102b3

@bors
Copy link
Contributor

@bors bors commented on 96102b3 Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 96102b3 Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging chromatic/rust/gh_11976_fail_bounds_check_str = 96102b3 into auto

@bors
Copy link
Contributor

@bors bors commented on 96102b3 Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromatic/rust/gh_11976_fail_bounds_check_str = 96102b3 merged ok, testing candidate = aa06bf4

@bors
Copy link
Contributor

@bors bors commented on 96102b3 Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 96102b3 Feb 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = aa06bf4

Please sign in to comment.