public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Willy Tarreau <w@1wt.eu>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] tools/nolibc/printf: Support negative variable width and precision
Date: Wed, 25 Mar 2026 23:03:47 +0000	[thread overview]
Message-ID: <20260325230347.5663ad33@pumpkin> (raw)
In-Reply-To: <eeddac13-6e6e-4a50-844c-becf5ff73de5@t-8ch.de>

On Wed, 25 Mar 2026 21:37:11 +0100
Thomas Weißschuh <linux@weissschuh.net> wrote:

> Hi David,
> 
> thanks again for your patch!
> 
> On 2026-03-23 11:22:47+0000, david.laight.linux@gmail.com wrote:
> > From: David Laight <david.laight.linux@gmail.com>
> > 
> > For (eg) "%*.*s" treat a negative field width as a request to left align
> > the output (the same as the '-' flag), and a negative precision to
> > request the default precision.  
> 
> This makes sense, so far so good.
> 
> > Set the default precision to -1 (not INT_MAX) and add explicit checks
> > to the string handling for negative values (makes the tet unsigned).  
> 
> 'tet'?

test - I wanted to say that the test:
	len = precision < 0 || precision >= 6 ? 6 : 0;
isn't actually a double comparison.
Perhaps it isn't needed.

> 
> > For numeric output check for 'precision >= 0' instead of testing
> > _NOLIBC_PF_FLAGS_CONTAIN(flags, '.').
> > This needs an inverted test, some extra goto and removes an indentation.
> > The changed conditionals fix printf("%0-#o", 0) - but '0' and '-' shouldn't
> > both be specified.  
> 
> Is this also related to the negative field width as described above?
> If yes, could you explain how? If not, please split it out.
> In general, the smaller the patches, the easier the review.

Everything except the 'if (width < 0)' test is one change.
It also changes v5 15/17, I did it as a delta (rather than a replacement
patch) because of the later changes.

The fix for printf("%0-#o", 0) (without these changes it generates "00")
happens because of the way the conditionals and gotos change.
Patch v5 15/17 that added zero padding and field precision had two
'goto prepend_sign', patch 16 (add octal) needs them to go opposite
sides of the 'if (sign_prefix == *out)' test.
With the changed conditionals you need both labels or ("%#o", 0)
always goes wrong.

> 
> > Best viewed with 'git diff -b' after being commited.  
> 
> This should go after '---'. No reason on its own to resend, though.
> 
> > Additional test cases added.  
> 
> No need to mention that, it is obvious from the diff :-)
> 
> > Signed-off-by: David Laight <david.laight.linux@gmail.com>
> > ---
> > 
> > I missed this bit in the earlier patches.
> > Size wise it is pretty neutral. It really seems to depend on how many registers
> > get saved across the call to _nolibc_u64toa_base() - gcc doesn't seem to use
> > the correct registers to avoid spills.
> > 
> > I did look at whether making 'width' negative at the top was better than
> > keeping a '-' flag - but it bloats things because you need the absolute value
> > at the bottom.
> > 
> >  tools/include/nolibc/stdio.h                 | 68 +++++++++++---------
> >  tools/testing/selftests/nolibc/nolibc-test.c |  5 +-
> >  2 files changed, 41 insertions(+), 32 deletions(-)
> > 
> > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
> > index 8f7e1948a651..b6d14a58cfe7 100644
> > --- a/tools/include/nolibc/stdio.h
> > +++ b/tools/include/nolibc/stdio.h
> > @@ -347,6 +347,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list
> >  	char *out;
> >  	const char *outstr;
> >  	unsigned int sign_prefix;
> > +	int got_width;  
> 
> bool?

There weren't any others in this file and I'm 'old school'...

	David

> 
> (...)
> 
> Otherwise looks good from what I understand.
> But smaller patches would really give me more confidence.
> 
> 
> Thomas


      reply	other threads:[~2026-03-25 23:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 11:22 [PATCH 1/1] tools/nolibc/printf: Support negative variable width and precision david.laight.linux
2026-03-25 20:37 ` Thomas Weißschuh
2026-03-25 23:03   ` David Laight [this message]

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=20260325230347.5663ad33@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=w@1wt.eu \
    /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