for now make to_string() less strict as we often don't want to crash the whole app just because some non-proper utf8 came in (through a message we can't neccesarily congtrol)

This commit is contained in:
holger krekel
2019-07-20 01:17:53 +02:00
parent 7a59da5f8f
commit 38eb708db8
2 changed files with 16 additions and 9 deletions

View File

@@ -1561,12 +1561,9 @@ pub fn to_string(s: *const libc::c_char) -> String {
let cstr = unsafe { CStr::from_ptr(s) };
cstr.to_str().map(|s| s.to_string()).unwrap_or_else(|err| {
eprintln!(
"Non utf8 string: '{:?}' ({:?})",
cstr.to_string_lossy(),
err
);
panic!("Non utf8 string: '{:?}' ({:?})", cstr.to_bytes(), err);
let lossy = cstr.to_string_lossy();
eprintln!("Non utf8 string: '{:?}' ({:?})", lossy, err);
lossy.to_string()
})
}