Skip to content

Commit

Permalink
fix: maybe handle non-UTF-8/null error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
decahedron1 committed Oct 10, 2024
1 parent b31f28a commit fbe8cbf
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,11 @@ macro_rules! ortsys {
pub(crate) use ortsys;

pub(crate) fn char_p_to_string(raw: *const c_char) -> Result<String> {
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;
Expand Down

0 comments on commit fbe8cbf

Please sign in to comment.