Re: [PATCH v6 2/4] rust: replace `CStr` with `core::ffi::CStr`
From: Tamir Duberstein
Date: Sun Feb 02 2025 - 09:40:58 EST
On Sun, Feb 2, 2025 at 7:54 AM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
>
> 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.
Ah, turns out Michal's patches removed functionality added in commit
a321f3ad0a5d ("rust: str: add {make,to}_{upper,lower}case() to
CString") which relied on this DerefMut impl. I've restored it all in
v7.