public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Sean Anderson <sean.anderson@seco.com>
Cc: "Pali Rohár" <pali@kernel.org>, "Simon Glass" <sjg@chromium.org>,
	u-boot@lists.denx.de, "Marek Behún" <marek.behun@nic.cz>
Subject: Re: [PATCH] malloc_simple: Remove usage of unsupported %zx format string
Date: Thu, 3 Feb 2022 16:18:27 -0500	[thread overview]
Message-ID: <20220203211827.GZ7515@bill-the-cat> (raw)
In-Reply-To: <a985637a-12dd-3619-86d8-af27b6875d7e@seco.com>

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

On Thu, Feb 03, 2022 at 02:28:23PM -0500, Sean Anderson wrote:
> 
> 
> On 2/3/22 2:25 PM, Sean Anderson wrote:
> > Hi Pali,
> > 
> > On 2/3/22 1:51 PM, Pali Rohár wrote:
> >> Replace %zx by %lx and cast size_t to ulong.
> >> 
> >> U-Boot currently prints garbage debug output:
> >> size=x, ptr=18, limit=18: 4002a000
> >> 
> >> With this change it prints correct debug data:
> >> size=18, ptr=18, limit=2000: 4002a000
> >> 
> >> Signed-off-by: Pali Rohár <pali@kernel.org>
> > 
> > This qualifier is implemented in vsprintf, but not tiny-printf,
> > and is widely used throughout the codebase. So perhaps a better
> > fix might be 
> > 
> > diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> > index f661fc6505..ad25bb7383 100644
> > --- a/lib/tiny-printf.c
> > +++ b/lib/tiny-printf.c
> > @@ -229,7 +229,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)
> >                                         ch = *fmt++;
> >                                 }
> >                         }
> > -                       if (ch == 'l') {
> > +                       if (ch == 'l' ||
> > +                           (sizeof(size_t) >= sizeof(int) && ch == 'z')) {
> >                                 ch = *(fmt++);
> >                                 islong = true;
> >                         }
> > --
> > 
> > which is not completely correct (since tiny-printf doesn't
> > support long longs), but will address the core issue.
> 
> Actually, we probably need something more like
> 
> if (ch == 'z') {
> 	ch = *(fmt++);
> 	islong = sizeof(size_t) >= sizeof(int);
> }
> 
> so that 32-bit arches still print the integer.

Right, but then we grow tiny-printf on the boards that really need to be
super concerned about space.  We have typically done what Pali proposes
here before of make the subset of code that runs under tiny-printf use
more restrictive and possibly slightly less optimal format characters.

-- 
Tom

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

  reply	other threads:[~2022-02-03 21:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 18:51 [PATCH] malloc_simple: Remove usage of unsupported %zx format string Pali Rohár
2022-02-03 19:25 ` Sean Anderson
2022-02-03 19:28   ` Sean Anderson
2022-02-03 21:18     ` Tom Rini [this message]
2022-02-03 21:19 ` Simon Glass
2022-02-04 10:48   ` Pali Rohár
2022-02-11 17:07 ` Tom Rini

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=20220203211827.GZ7515@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --cc=sean.anderson@seco.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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