Skip to content

Commit fbe8cbf

Browse files
committed
fix: maybe handle non-UTF-8/null error messages
1 parent b31f28a commit fbe8cbf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,11 @@ macro_rules! ortsys {
273273
pub(crate) use ortsys;
274274

275275
pub(crate) fn char_p_to_string(raw: *const c_char) -> Result<String> {
276-
let c_string = unsafe { CStr::from_ptr(raw.cast_mut()).to_owned() };
277-
match c_string.into_string() {
278-
Ok(string) => Ok(string),
279-
Err(e) => Err(Error::wrap(e))
276+
if raw.is_null() {
277+
return Ok(String::new());
280278
}
281-
.map_err(Error::wrap)
279+
let c_string = unsafe { CStr::from_ptr(raw.cast_mut()).to_owned() };
280+
Ok(c_string.to_string_lossy().to_string())
282281
}
283282

284283
pub(crate) struct PrivateTraitMarker;

0 commit comments

Comments
 (0)