mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Making str::from_cstr UTF-8 safe
This commit is contained in:
parent
a185b10647
commit
fec36de94e
@ -217,16 +217,16 @@ Function: from_cstr
|
|||||||
Create a Rust string from a null-terminated C string
|
Create a Rust string from a null-terminated C string
|
||||||
*/
|
*/
|
||||||
unsafe fn from_cstr(cstr: sbuf) -> str {
|
unsafe fn from_cstr(cstr: sbuf) -> str {
|
||||||
let res = "";
|
let res = [];
|
||||||
let start = cstr;
|
let start = cstr;
|
||||||
let curr = start;
|
let curr = start;
|
||||||
let i = 0u;
|
let i = 0u;
|
||||||
while *curr != 0u8 {
|
while *curr != 0u8 {
|
||||||
push_byte(res, *curr);
|
vec::push(res, *curr);
|
||||||
i += 1u;
|
i += 1u;
|
||||||
curr = ptr::offset(start, i);
|
curr = ptr::offset(start, i);
|
||||||
}
|
}
|
||||||
ret res;
|
ret from_bytes(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user