Skip to content

Commit 3b818ed

Browse files
committed
std and extra: use as_c_str instead of as_buf in a couple places
These uses are assuming the strings are null terminated, so it should be using `as_c_str` instead of `as_buf`
1 parent cf75330 commit 3b818ed

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

src/libstd/rt/borrowck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ unsafe fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
7676
match try_take_task_borrow_list() {
7777
None => { // not recording borrows
7878
let msg = "borrowed";
79-
do msg.as_buf |msg_p, _| {
79+
do msg.as_c_str |msg_p| {
8080
sys::begin_unwind_(msg_p as *c_char, file, line);
8181
}
8282
}
@@ -92,7 +92,7 @@ unsafe fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
9292
sep = " and at ";
9393
}
9494
}
95-
do msg.as_buf |msg_p, _| {
95+
do msg.as_c_str |msg_p| {
9696
sys::begin_unwind_(msg_p as *c_char, file, line)
9797
}
9898
}
@@ -231,7 +231,7 @@ pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint,
231231
let br = borrow_list.pop();
232232
if br.box != a || br.file != file || br.line != line {
233233
let err = fmt!("wrong borrow found, br=%?", br);
234-
do err.as_buf |msg_p, _| {
234+
do err.as_c_str |msg_p| {
235235
sys::begin_unwind_(msg_p as *c_char, file, line)
236236
}
237237
}

src/libstd/sys.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,19 @@ pub trait FailWithCause {
123123

124124
impl FailWithCause for ~str {
125125
fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! {
126-
do cause.as_buf |msg_buf, _msg_len| {
127-
do file.as_buf |file_buf, _file_len| {
128-
unsafe {
129-
let msg_buf = cast::transmute(msg_buf);
130-
let file_buf = cast::transmute(file_buf);
131-
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
132-
}
126+
do cause.as_c_str |msg_buf| {
127+
do file.as_c_str |file_buf| {
128+
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
133129
}
134130
}
135131
}
136132
}
137133

138134
impl FailWithCause for &'static str {
139135
fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! {
140-
do cause.as_buf |msg_buf, _msg_len| {
141-
do file.as_buf |file_buf, _file_len| {
142-
unsafe {
143-
let msg_buf = cast::transmute(msg_buf);
144-
let file_buf = cast::transmute(file_buf);
145-
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
146-
}
136+
do cause.as_c_str |msg_buf| {
137+
do file.as_c_str |file_buf| {
138+
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
147139
}
148140
}
149141
}

src/libstd/unstable/lang.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ pub fn fail_bounds_check(file: *c_char, line: size_t,
5656
index: size_t, len: size_t) {
5757
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
5858
len as int, index as int);
59-
do msg.as_buf |p, _len| {
60-
fail_(p as *c_char, file, line);
59+
do msg.as_c_str |buf| {
60+
fail_(buf, file, line);
6161
}
6262
}
6363

0 commit comments

Comments
 (0)