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:
@@ -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()) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user