mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: david.laight.linux@gmail.com
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 21:37:11 +0100	[thread overview]
Message-ID: <eeddac13-6e6e-4a50-844c-becf5ff73de5@t-8ch.de> (raw)
In-Reply-To: <20260323112247.3196-1-david.laight.linux@gmail.com>

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

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

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

(...)

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


Thomas

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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 11:22 david.laight.linux
2026-03-25 20:37 ` Thomas Weißschuh [this message]
2026-03-25 23:03   ` David Laight

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=eeddac13-6e6e-4a50-844c-becf5ff73de5@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®