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 9D7DB5A027F for ; Fri, 1 Dec 2023 01:00:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1701388803; bh=2IUlgr229Y2C02O0dPUjk+ZwSewOWq6lFNnyPrTZY1M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HBgWhFh3vQLXYRy/P+IBEppHIO/JbVn6XsLgDtsyfKxzWmKNd46qcsnNlZHIZJ6AD VQIyJzcVRVsCkMW5qFJkA+8As+WXJNUXOndGc5FTbTOAh3gMXXaJtYFbKrK++SWYxh h1BUPiYWW4vOqaVKCT+WmkGH6cU8Gjc++XtBjjEI= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ShCqR3tkzz4xVW; Fri, 1 Dec 2023 11:00:03 +1100 (AEDT) Date: Fri, 1 Dec 2023 10:10:51 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 1/4] treewide: Use 'z' length modifier for size_t/ssize_t conversions Message-ID: References: <20231129134610.3796809-1-sbrivio@redhat.com> <20231129134610.3796809-2-sbrivio@redhat.com> <20231130100646.11566f82@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8crAwweZAlWqxmtG" Content-Disposition: inline In-Reply-To: <20231130100646.11566f82@elisabeth> Message-ID-Hash: UWFESMI7JJ62OHNLAB5FV7EXRWJVFNBQ X-Message-ID-Hash: UWFESMI7JJ62OHNLAB5FV7EXRWJVFNBQ 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: --8crAwweZAlWqxmtG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 30, 2023 at 10:06:46AM +0100, Stefano Brivio wrote: > On Thu, 30 Nov 2023 11:15:47 +1100 > David Gibson wrote: >=20 > > On Wed, Nov 29, 2023 at 02:46:07PM +0100, Stefano Brivio wrote: > > > Types size_t and ssize_t are not necessarily long, it depends on the > > > architecture. =20 > >=20 > > Most LGTM, but a couple of nits: > >=20 > > [snip] > > > @@ -106,7 +106,7 @@ void *packet_get_do(const struct pool *p, size_t = idx, size_t offset, > > > =20 > > > if (p->pkt[idx].offset + len + offset > p->buf_size) { > > > if (func) { > > > - trace("packet offset plus length %lu from size %lu, " > > > + trace("packet offset plus length %lu from size %zu, " =20 > >=20 > > The change here is certainly correct. But the remaining %lu is > > dubious. The value given is the sum of a uint32_t and two size_t, so > > it could depend on platform what exactly that will be promoted to. I > > think we should probably either cast the result explicitly to (size_t) > > and use %zu, or cast to (uint32_t) and use "%" PRIu32. > >=20 > > [snip] > > > diff --git a/tcp_splice.c b/tcp_splice.c > > > index a5c1332..8d08bb4 100644 > > > --- a/tcp_splice.c > > > +++ b/tcp_splice.c > > > @@ -321,7 +321,7 @@ static int tcp_splice_connect_finish(const struct= ctx *c, > > > =20 > > > if (fcntl(conn->pipe[side][0], F_SETPIPE_SZ, > > > c->tcp.pipe_size)) { > > > - trace("TCP (spliced): cannot set %d->%d pipe size to %lu", > > > + trace("TCP (spliced): cannot set %d->%d pipe size to %zu", > > > side, !side, c->tcp.pipe_size); > > > } > > > } > > > @@ -554,7 +554,7 @@ retry: > > > readlen =3D splice(conn->s[fromside], NULL, > > > conn->pipe[fromside][1], NULL, c->tcp.pipe_size, > > > SPLICE_F_MOVE | SPLICE_F_NONBLOCK); > > > - trace("TCP (spliced): %li from read-side call", readlen); > > > + trace("TCP (spliced): %zi from read-side call", readlen); > > > if (readlen < 0) { > > > if (errno =3D=3D EINTR) > > > goto retry; > > > @@ -580,7 +580,7 @@ eintr: > > > written =3D splice(conn->pipe[fromside][0], NULL, > > > conn->s[!fromside], NULL, to_write, > > > SPLICE_F_MOVE | more | SPLICE_F_NONBLOCK); > > > - trace("TCP (spliced): %li from write-side call (passed %lu)", > > > + trace("TCP (spliced): %zi from write-side call (passed %zu)", > > > written, to_write); =20 > >=20 > > 'to_write' is actually an ssize_t which would suggest %zi. However > > looking at the code, I think to_write probably *should* be a size_t > > instead. >=20 > Oops, I didn't notice. Well, I know we're passing it to splice(), but > we're also using it like this: >=20 > if (!never_read && written < to_write) { > to_write -=3D written; > goto retry; > } >=20 > so I'd rather keep it as ssize_t for the moment (and re-spin this > series with a %zi here), just in case we happen to do something silly > with it and ssize_t is saving us. Eh.. that's the only place we subtract, and the literal line above verifies that the result will still be positive, so I think we're safe. But, whatever. --=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 --8crAwweZAlWqxmtG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmVpFnUACgkQzQJF27ox 2GdpiQ/8CeO5RFWTDFqN1RlLZFjnWi1JU/Mw6OAY/5uNJJ/zWv3GF5rIB0cnp1bQ fXTmqPko43E+FcoSwkR7Lh26BCp3+cEW5hmD7Th78WQ/wuzI3TaVGaB97Z40fzkV SYfJsNixVsJy3lc3HG9292KQ5mkhEdzOJYZ8Eg7WlbD3jBrdY4UaJJ4x2HRf83uV OX8m5LJTKyxUHyou6wQYm++vvgvdA7zAp+jX5X/ab7Y0XshhIYrcW0E9rLSH/0pw Yf6/pXXZaqYYBQpdRfKc+YMX55xaCHn8eFnN8/5EUfHBxuJEjeNyomMB9BMy6jsB 7TUZvRnFCthgdPeM4mlQCPZO4FcomJWg9rqC0jRnkXQFyzbxQD4oOoFYSoypmXcI 3MGXUJbD0k245Azpzb/WUUQVs9c15FklRVGo3QmWGqu0tnvRHOs2PPNY7lOqOZ0Z W+5hEUaGOTAMW0ZXp099pLJm4dh2UlaKWQbQBVdfAGyCNt93dX6EQNMABnystgZ4 ZR8v4QEk51pCbP5KSwM1PR+My0BFk6zIYgVXW7tCMLDX8ybT0A8ZT+t0wUPtgn0/ 9wLCkueL6R5CmLNbLtHHweCNuQWXZjyuckNXN8iiu7DM/9f5OYGwurJV49Leq3v9 767cGvE66f65JZC7/wEr62KN6FhEXFfy7gsfwtX+7bVLvSn5Elw= =2S5x -----END PGP SIGNATURE----- --8crAwweZAlWqxmtG--