From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top, lemmi@nerd2nerd.org
Subject: Re: [PATCH 2/4] packet: Offset plus length is not always uint32_t, but it's always size_t
Date: Thu, 30 Nov 2023 10:07:00 +0100 [thread overview]
Message-ID: <20231130100700.10fe5354@elisabeth> (raw)
In-Reply-To: <ZWfU6JZhGWQmUDyI@zatzit>
On Thu, 30 Nov 2023 11:18:48 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:
> On Wed, Nov 29, 2023 at 02:46:08PM +0100, Stefano Brivio wrote:
> > According to gcc, PRIu32 matches the type of the argument we're
> > printing here on both 64 and 32-bits architectures. According to
> > Clang, though, that's not the case, as the result of the sum is an
> > unsigned long on 64-bit.
> >
> > Use the z modifier, given that we're summing uint32_t to size_t, and
> > the result is at most promoted to size_t.
>
> Heh, sorry, obviously hadn't read this patch when I commented on this
> spot in the first one. The problem here is that the final promoted
> type depends on whether size_t is wider than uint32_t or not, which
> can vary with architecture.
...I'm not sure if it's just a matter of warnings, but gcc is perfectly
happy with PRIu32 for uint32_t + size_t on x86_64, so on top of the
architecture, promotion rules also seem to vary between compilers. Or
maybe it just doesn't complain about the possible format truncation.
> That said, I doubt we're likely to support anything with a size_t
> strictly *less* than 32-bits, so %zu is probably safe.
Ah, yes, I took that for granted. Looking into older architectures
where C would commonly be used, it looks like 16 bits of size_t would
only suffice for *selected versions* of PDP-11 (PDP-11/15 and
PDP-11/20, but not PDP-11/45 already, because the addressing space is
larger than 64 KiB).
Indeed there are 8 and 16 bits processors, but there doesn't appear to
be any other modern architecture where 16 bits suffice for addressable
memory (by design).
--
Stefano
next prev parent reply other threads:[~2023-11-30 9:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-29 13:46 [PATCH 0/4] Fix build warnings and errors for 32-bit and musl Stefano Brivio
2023-11-29 13:46 ` [PATCH 1/4] treewide: Use 'z' length modifier for size_t/ssize_t conversions Stefano Brivio
2023-11-30 0:15 ` David Gibson
2023-11-30 9:06 ` Stefano Brivio
2023-11-30 23:10 ` David Gibson
2023-11-29 13:46 ` [PATCH 2/4] packet: Offset plus length is not always uint32_t, but it's always size_t Stefano Brivio
2023-11-30 0:18 ` David Gibson
2023-11-30 9:06 ` Stefano Brivio
2023-11-30 9:07 ` Stefano Brivio [this message]
2023-11-30 23:12 ` David Gibson
2023-11-29 13:46 ` [PATCH 3/4] tcp, tcp_splice: CONN_IDX subtraction of pointers isn't always long Stefano Brivio
2023-11-29 13:58 ` Stefano Brivio
2023-11-30 0:27 ` David Gibson
2023-11-30 9:07 ` Stefano Brivio
2023-11-30 23:13 ` David Gibson
2023-11-29 13:46 ` [PATCH 4/4] port_fwd, util: Include additional headers to fix build with musl Stefano Brivio
2023-11-30 0:30 ` David Gibson
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=20231130100700.10fe5354@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=lemmi@nerd2nerd.org \
--cc=passt-dev@passt.top \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).