From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id C74105A027F for ; Fri, 1 Dec 2023 01:00:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1701388803; bh=Nr4ejryRWmR2C6WBvgs+XVAMPNpfIgef5MuGNQQ0NL8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OpQXuZwhqZjda/y/ewdDAUw2kYrzaPaJq3IN8Dqez88eTKemdR8/LXYk+LSZXTq60 H3EI8SVMiXJByMt5AViDkMKdtByA1yqrczQCi7wlFIw9+6CbYi/fHnZH5pSbcp+9Rj BIe93abjf7q0m+fYbgefmmlwoVsLyQ51i3qaPHfA= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ShCqR46Xcz4xVg; Fri, 1 Dec 2023 11:00:03 +1100 (AEDT) Date: Fri, 1 Dec 2023 10:12:08 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/4] packet: Offset plus length is not always uint32_t, but it's always size_t Message-ID: References: <20231129134610.3796809-1-sbrivio@redhat.com> <20231129134610.3796809-3-sbrivio@redhat.com> <20231130100700.10fe5354@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tAg4+6si+SsT+bzg" Content-Disposition: inline In-Reply-To: <20231130100700.10fe5354@elisabeth> Message-ID-Hash: R33NS6CRBGPAT5RYIUUMLLRGG3C2PPZZ X-Message-ID-Hash: R33NS6CRBGPAT5RYIUUMLLRGG3C2PPZZ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, lemmi@nerd2nerd.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --tAg4+6si+SsT+bzg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 30, 2023 at 10:07:00AM +0100, Stefano Brivio wrote: > On Thu, 30 Nov 2023 11:18:48 +1100 > David Gibson wrote: >=20 > > 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. > > >=20 > > > Use the z modifier, given that we're summing uint32_t to size_t, and > > > the result is at most promoted to size_t. =20 > >=20 > > 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. >=20 > ...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. Huh.. that's pretty surprising. > > That said, I doubt we're likely to support anything with a size_t > > strictly *less* than 32-bits, so %zu is probably safe. >=20 > 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). >=20 > 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). Right. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --tAg4+6si+SsT+bzg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmVpFscACgkQzQJF27ox 2GcD0BAAp5Ju9pWgOdOS7I3/KuZFK9HloOrr3crP8Trm3mZASDUOQjpJW2qpuRZF SvRgqIcQtK9H/v6R3hsJX0zILJoOcYmHJRTkKLo+cvNx5dcOXKWuSWYMAiLfkEr1 zMREYugVzc0uys6HddkFcBM/+C7Ecd2vRTZOGjyVUaI+0ZZV/ICTUF/ELikNeQLC niO3NviwV8ffk8bTAa96UVGM0cRsY5CXocNLHMxU16k+60c7hwe6eqCqxqf4a4xp l3BGcZZs8MarDF8fhUc49ppVKCYsbeTB8Ij6wCBUOeu1GjXLi+bn3iWxJ7Sk7G4H lEbLAgRwvS8qacq2CGlCo4kJGE5yZ7EGi+bGkxBtmd06kyV9DrFK6dm14t3D1W0T NzVeYxWVdNjjwqE4nXGU04PbNgUJ1AhG8L5fXrJUlSEIPPCr39DvXyNciZ/HYqhv LULOLgrm+AnlEfQWnKd9+axzUQpKwfN6pk1d7ST6BSogJEQtQux/XH9enHi8KdZ7 qmSYo+aYFrzxx0ep+g1e6n12Q/j1AtQzTZBMgxsft5XNku4VwwkYZe6ZH9WvHSTV ZU8MFhzSinkxa0kIqVIGYDkkIdfUuFWpJgfdi7k3ABS1y2q6KWj3mMYHH51sYtoy AGhHqcUa4DQJRbgTadiCS6RHeswoFHePMc67CO5xHIJNze6fyG8= =VrOh -----END PGP SIGNATURE----- --tAg4+6si+SsT+bzg--