limit unsafe regions

This commit is contained in:
Dustin J. Mitchell 2022-02-01 00:48:49 +00:00
parent 22a6857c1b
commit 03ffb6ce83
3 changed files with 10 additions and 7 deletions

View file

@ -52,7 +52,8 @@ impl<'a> TCString<'a> {
/// the lifetime promised by C.
pub(crate) unsafe fn from_arg(tcstring: *mut TCString<'a>) -> Self {
debug_assert!(!tcstring.is_null());
*(Box::from_raw(tcstring))
// SAFETY: see docstring
unsafe { *(Box::from_raw(tcstring)) }
}
/// Borrow a TCString from C as an argument.
@ -64,7 +65,8 @@ impl<'a> TCString<'a> {
/// the lifetime promised by C.
pub(crate) unsafe fn from_arg_ref(tcstring: *mut TCString<'a>) -> &'a mut Self {
debug_assert!(!tcstring.is_null());
&mut *tcstring
// SAFETY: see docstring
unsafe { &mut *tcstring }
}
/// Get a regular Rust &str for this value.