All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Cheng Li <im.lechain@gmail.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
	"Willy Tarreau" <w@1wt.eu>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] tools/nolibc: add support zero pad (0) in printf
Date: Sun, 1 Feb 2026 08:56:24 +0000	[thread overview]
Message-ID: <20260201085624.7fbc4c59@pumpkin> (raw)
In-Reply-To: <CAAZOWcLmqWDubmQZmGTrYgw35WAQXNSr4K=3a8wF0=6_yCEktw@mail.gmail.com>

On Sun, 1 Feb 2026 08:49:37 +0800
Cheng Li <im.lechain@gmail.com> wrote:

> David Laight <david.laight.linux@gmail.com> 于2026年1月31日周六 20:32写道:
> >
> > On Sat, 31 Jan 2026 11:18:49 +0100
> > Thomas Weißschuh <linux@weissschuh.net> wrote:
> >  
> > > Hey Cheng,
> > >
> > > Jan 30, 2026 09:37:51 licheng.li <im.lechain@gmail.com>:
> > >  
> > > > From: Cheng Li <im.lechain@gmail.com>
> > > >
> > > > This patch correctly implements the '0' flag in __nolibc_printf() to
> > > > allow zero-padding for numeric and pointer outputs.  
> > >
> > > Thanks for (all of) your patches.
> > > I am not sure when exactly I can take a proper look at them.
> > > As we are currently fairly late in the 6.20/7.0 development cycle I would like move your patches into the next one.
> > > We can still discuss the patches and you can send new revisions and patches,
> > > but they won't be picked up until in a few weeks.  
> >
> > Gives me time to re-write them :-)
> >
> > There is still a bug in the 'align left' code as well.
> > snprintf(buf, 21, "%-25s", "abcd") outputs 20 spaces not "abcd" followed by 16.
> > Easiest fix is to move the truncation in the cb() function.  
> 
> Hi David,
> 
> I did a double-check on the `snprintf(buf, 21, "%-25s", "abcd")` case
> with the v4 patch.
> 
> In my testing, the output content is actually correct ("abcd" followed
> by 16 spaces),
> and the return value is 25, which complies with the standard
> (representing the length
> if the buffer were infinite).

I was probably checking a slightly different version where the '-'
just caused the truncated "abcd" be output before the pad.

> 
> **However**, you are right to be concerned about the logic. Upon
> closer inspection,
> I realized there is a potential **buffer overflow risk**.
> 
...
> 
> Therefore, I am perfectly happy to drop my current left-alignment
> patch entirely and
> wait for your refactor, as it provides a much safer architecture."

I've got it 'mostly rewritten', I'll remove your patches for "%-2s" from
the front before I submit them.
I'll put that change in early.

	David

      reply	other threads:[~2026-02-01  8:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30  8:37 [PATCH 1/2] tools/nolibc: add support zero pad (0) in printf licheng.li
2026-01-30  8:37 ` [PATCH 2/2] selftests/nolibc: add tests for printf zero padding (0) licheng.li
2026-01-30 10:02 ` [PATCH 1/2] tools/nolibc: add support zero pad (0) in printf David Laight
2026-01-30 10:12   ` Cheng Li
2026-01-30 14:58     ` David Laight
2026-01-31  3:44       ` Cheng Li
2026-01-31 10:18 ` Thomas Weißschuh
2026-01-31 12:32   ` David Laight
2026-02-01  0:49     ` Cheng Li
2026-02-01  8:56       ` 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=20260201085624.7fbc4c59@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=im.lechain@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.