[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABm2a9egd7xq5OwEB+pq21wSPJS-89wY5Z3J8Kpay+3EsywDpQ@mail.gmail.com>
Date: Mon, 28 Jul 2025 16:39:41 -0300
From: Christian <christiansantoslima21@...il.com>
To: Kane York <kanepyork@...il.com>
Cc: a.hindborg@...nel.org, alex.gaynor@...il.com, aliceryhl@...gle.com,
benno.lossin@...ton.me, bjorn3_gh@...tonmail.com, boqun.feng@...il.com,
dakr@...nel.org, gary@...yguo.net, linux-kernel@...r.kernel.org,
ojeda@...nel.org, richard120310@...il.com, rust-for-linux@...r.kernel.org,
tmgross@...ch.edu, ~lkcamp/patches@...ts.sr.ht
Subject: Re: [PATCH v8] rust: transmute: Add methods for FromBytes trait
Hi, Kane.
> > +// SAFETY: If all bit patterns are acceptable for individual values in an array, then all bit
> > +// patterns are also acceptable for arrays of that type.
> > +unsafe impl<T: FromBytes> FromBytes for [T] {
> > + fn from_bytes(bytes: &[u8]) -> Option<&Self> {
> > + let slice_ptr = bytes.as_ptr().cast::<T>();
> > + if bytes.len() % ::core::mem::size_of::<T>() == 0 && slice_ptr.is_aligned() {
> > + // SAFETY: Since the code checks the size and alignment, the slice is valid.
> > + unsafe { Some(::core::slice::from_raw_parts(slice_ptr, bytes.len())) }
>
> This is incorrect -- the second argument to slice::from_raw_parts is the
> element count, not the byte count.
I don't understand, did you mean that the safety comment should be
changed or the argument? If you can explain in more detail.
Thanks,
Christian
Powered by blists - more mailing lists