From fbe8cbf0e94c36c23c7ec5b2ecf93a19588e201d Mon Sep 17 00:00:00 2001 From: "Carson M." Date: Thu, 10 Oct 2024 09:12:07 -0500 Subject: [PATCH] fix: maybe handle non-UTF-8/null error messages --- src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ed8b9a1..4e51705 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,12 +273,11 @@ macro_rules! ortsys { pub(crate) use ortsys; pub(crate) fn char_p_to_string(raw: *const c_char) -> Result { - let c_string = unsafe { CStr::from_ptr(raw.cast_mut()).to_owned() }; - match c_string.into_string() { - Ok(string) => Ok(string), - Err(e) => Err(Error::wrap(e)) + if raw.is_null() { + return Ok(String::new()); } - .map_err(Error::wrap) + let c_string = unsafe { CStr::from_ptr(raw.cast_mut()).to_owned() }; + Ok(c_string.to_string_lossy().to_string()) } pub(crate) struct PrivateTraitMarker;