Skip to content

Commit

Permalink
TIFU; Keep unsafe out of the public api.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorrenbiffin committed Apr 14, 2024
1 parent 744c220 commit f0e99f0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use crate::error::CStringError;


/// TODO
pub unsafe fn try_unwrap_cstr<'out>(bytes: *const i8) -> Result<&'out str, CStringError> {
pub fn try_unwrap_cstr<'out>(bytes: *const i8) -> Result<&'out str, CStringError> {
if bytes.is_null() {
return Err(CStringError::Uninitialized);
}

match CStr::from_ptr(bytes).to_str() {
Ok(c_str) => Ok(c_str),
Err(error) => Err(CStringError::Utf8Error(error)),
unsafe {
match CStr::from_ptr(bytes).to_str() {
Ok(c_str) => Ok(c_str),
Err(error) => Err(CStringError::Utf8Error(error)),
}
}
}

0 comments on commit f0e99f0

Please sign in to comment.