[PATCH] malloc_simple: Remove usage of unsupported %zx format string

Tom Rini trini at konsulko.com
Thu Feb 3 22:18:27 CET 2022


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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20220203/702fdb3b/attachment.sig>


More information about the U-Boot mailing list