public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, lemmi@nerd2nerd.org
Subject: Re: [PATCH 1/4] treewide: Use 'z' length modifier for size_t/ssize_t conversions
Date: Fri, 1 Dec 2023 10:10:51 +1100	[thread overview]
Message-ID: <ZWkWe5IwZpQUnjzx@zatzit> (raw)
In-Reply-To: <20231130100646.11566f82@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 3345 bytes --]

On Thu, Nov 30, 2023 at 10:06:46AM +0100, Stefano Brivio wrote:
> On Thu, 30 Nov 2023 11:15:47 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > 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.  
> > 
> > Most LGTM, but a couple of nits:
> > 
> > [snip]
> > > @@ -106,7 +106,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset,
> > >  
> > >  	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, "  
> > 
> > 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.
> > 
> > [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,
> > >  
> > >  			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 = 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 == EINTR)
> > >  				goto retry;
> > > @@ -580,7 +580,7 @@ eintr:
> > >  		written = 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);  
> > 
> > '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.
> 
> Oops, I didn't notice. Well, I know we're passing it to splice(), but
> we're also using it like this:
> 
> 		if (!never_read && written < to_write) {
> 			to_write -= written;
> 			goto retry;
> 		}
> 
> 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.

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-12-01  0:00 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 [this message]
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
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=ZWkWe5IwZpQUnjzx@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=lemmi@nerd2nerd.org \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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).