Skip to content

Commit 2d9d8aa

Browse files
committed
rust: replace str_from_null_terminated_ptr with ffi::CStr::from_ptr
This was added in Rust 1.64.
1 parent 666b677 commit 2d9d8aa

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/rust/bitbox02/src/util.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ pub fn str_from_null_terminated(input: &[u8]) -> Result<&str, ()> {
4141
/// # Safety `ptr` must be not null and be a null terminated string. The resulting string is only
4242
/// valid as long the memory pointed to by `ptr` is valid.
4343
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(()))
44+
core::ffi::CStr::from_ptr(ptr.cast()).to_str().or(Err(()))
4745
}
4846

4947
/// Macro for creating a stack allocated buffer with the content of a string and a null-terminator

0 commit comments

Comments
 (0)