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

Sean Anderson sean.anderson at seco.com
Thu Feb 3 20:25:44 CET 2022


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.

--Sean



More information about the U-Boot mailing list