From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Quentin Schulz <foss+uboot@0leil.net>
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
u-boot@lists.denx.de, Quentin Schulz <quentin.schulz@cherry.de>
Subject: Re: [PATCH] cmd/mem.c: fix undefined behavior in mem cmp
Date: Fri, 27 Sep 2024 20:56:18 +0200 [thread overview]
Message-ID: <87bk09kjsd.fsf@prevas.dk> (raw)
In-Reply-To: <20240927-cmd-mem-undefined-v1-1-56fa57d0927b@cherry.de> (Quentin Schulz's message of "Fri, 27 Sep 2024 18:37:43 +0200")
Quentin Schulz <foss+uboot@0leil.net> writes:
> From: Quentin Schulz <quentin.schulz@cherry.de>
>
> My linter complains that "When using void pointers in calculations, the
> behaviour is undefined".
>
> GCC does say that "In GNU C, addition and subtraction operations are
> supported on pointers to void"[1] but this hints at this only being
> supported in the GNU flavor of C. And I assume U-Boot may want to be
> compiled with clang/llvm?
>
> Let's fix that warning by casting the void pointer to a u8 pointer since
> the size variable unit is byte.
>
> [1] https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html
>
No, let's please not. Try enabling -Wpointer-arith and see how much
churn that would require all over the tree (doing it in this one place
would be pointless), and all the casts would make the code much much
harder to read.
We do rely on lots of gcc extensions, and Clang has documented that it
"aims to support a broad range of GCC extensions". Arithmetic on void is
one of them, and that's not going to go away.
Rasmus
next prev parent reply other threads:[~2024-09-27 18:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-27 16:37 [PATCH] cmd/mem.c: fix undefined behavior in mem cmp Quentin Schulz
2024-09-27 18:56 ` Rasmus Villemoes [this message]
2024-09-30 8:38 ` Quentin Schulz
2024-09-30 9:54 ` Rasmus Villemoes
2024-10-14 13:13 ` Quentin Schulz
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=87bk09kjsd.fsf@prevas.dk \
--to=rasmus.villemoes@prevas.dk \
--cc=foss+uboot@0leil.net \
--cc=quentin.schulz@cherry.de \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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