Skip to content

Commit fec36de

Browse files
committed
Making str::from_cstr UTF-8 safe
1 parent a185b10 commit fec36de

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/libcore/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ Function: from_cstr
217217
Create a Rust string from a null-terminated C string
218218
*/
219219
unsafe fn from_cstr(cstr: sbuf) -> str {
220-
let res = "";
220+
let res = [];
221221
let start = cstr;
222222
let curr = start;
223223
let i = 0u;
224224
while *curr != 0u8 {
225-
push_byte(res, *curr);
225+
vec::push(res, *curr);
226226
i += 1u;
227227
curr = ptr::offset(start, i);
228228
}
229-
ret res;
229+
ret from_bytes(res);
230230
}
231231

232232
/*

0 commit comments

Comments
 (0)