Re: [PATCH v6 2/4] rust: replace `CStr` with `core::ffi::CStr`
From: Tamir Duberstein
Date: Sun Feb 02 2025 - 07:55:29 EST
On Sun, Feb 2, 2025 at 7:20 AM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
>
> impl DerefMut for CString {
> fn deref_mut(&mut self) -> &mut Self::Target {
> - // SAFETY: A `CString` is always NUL-terminated and contains no other
> - // NUL bytes.
> - unsafe { CStr::from_bytes_with_nul_unchecked_mut(self.buf.as_mut_slice()) }
> + // SAFETY: Properties of `bytes` guaranteed by the safety precondition.
> + unsafe { &mut *(self.buf.as_mut_slice() as *mut [u8] as *mut CStr) }
> }
> }
Whoops, this safety comment is nonsense. I'll use the one from `impl
Deref` above in v7...or just remove this impl altogether. I'm not sure
what the use for `&mut CStr` would be.