From: Christian <christiansantoslima21@gmail.com>
To: Kane York <kanepyork@gmail.com>
Cc: a.hindborg@kernel.org, alex.gaynor@gmail.com,
aliceryhl@google.com, benno.lossin@proton.me,
bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org,
gary@garyguo.net, linux-kernel@vger.kernel.org,
ojeda@kernel.org, richard120310@gmail.com,
rust-for-linux@vger.kernel.org, tmgross@umich.edu,
~lkcamp/patches@lists.sr.ht
Subject: Re: [PATCH v8] rust: transmute: Add methods for FromBytes trait
Date: Mon, 28 Jul 2025 16:39:41 -0300 [thread overview]
Message-ID: <CABm2a9egd7xq5OwEB+pq21wSPJS-89wY5Z3J8Kpay+3EsywDpQ@mail.gmail.com> (raw)
In-Reply-To: <CABeNrKVYy=9QKvTwnDPfRhXuJLCFgA9bbvd34V-P8jHLEJSGEg@mail.gmail.com>
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
next prev parent reply other threads:[~2025-07-28 19:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 4:28 [PATCH v8] rust: transmute: Add methods for FromBytes trait Christian S. Lima
2025-06-25 2:39 ` kernel test robot
2025-07-07 5:14 ` Alexandre Courbot
2025-07-14 22:16 ` Christian
2025-07-22 14:06 ` Alexandre Courbot
2025-07-25 18:37 ` Christian
2025-07-26 2:57 ` Alexandre Courbot
2025-07-27 1:37 ` Kane York
2025-07-28 19:39 ` Christian [this message]
2025-07-28 21:21 ` K. York
2025-08-01 12:26 ` Alexandre Courbot
2025-08-01 15:35 ` Miguel Ojeda
2025-08-01 17:47 ` Christian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABm2a9egd7xq5OwEB+pq21wSPJS-89wY5Z3J8Kpay+3EsywDpQ@mail.gmail.com \
--to=christiansantoslima21@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=kanepyork@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=richard120310@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=~lkcamp/patches@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).