rusticl/util: add missing comment and assert to char_arr_to_cstr

I forgot to push those changes...

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33703>
This commit is contained in:
Karol Herbst
2025-02-24 08:22:58 +01:00
committed by Marge Bot
parent e4f31b8744
commit 4975ac79ef
@@ -12,9 +12,15 @@ pub fn c_string_to_string(cstr: *const c_char) -> String {
String::from(res.unwrap_or(""))
}
/// Simple wrapper around [`CStr::from_ptr`] to bind the lifetime to a slice containing the
/// nul-terminated string.
///
/// # Safety
///
/// Same as [`CStr::from_ptr`]
pub unsafe fn char_arr_to_cstr(c_str: &[c_char]) -> &CStr {
// We make sure that at least the end of the slice is nul-terminated. We don't really care if
// there is another nul within the slice.
debug_assert_eq!(c_str.last().copied(), Some(b'\0' as c_char));
unsafe { CStr::from_ptr(c_str.as_ptr()) }
}