We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 666b677 commit 2d9d8aaCopy full SHA for 2d9d8aa
src/rust/bitbox02/src/util.rs
@@ -41,9 +41,7 @@ pub fn str_from_null_terminated(input: &[u8]) -> Result<&str, ()> {
41
/// # Safety `ptr` must be not null and be a null terminated string. The resulting string is only
42
/// valid as long the memory pointed to by `ptr` is valid.
43
pub unsafe fn str_from_null_terminated_ptr<'a>(ptr: *const u8) -> Result<&'a str, ()> {
44
- let len = strlen_ptr(ptr);
45
- let s = core::slice::from_raw_parts(ptr, len as _);
46
- core::str::from_utf8(s).or(Err(()))
+ core::ffi::CStr::from_ptr(ptr.cast()).to_str().or(Err(()))
47
}
48
49
/// Macro for creating a stack allocated buffer with the content of a string and a null-terminator
0 commit comments