On 3/20/25 3:00 PM, Quentin Schulz wrote:
Hi Marek,
On 3/20/25 12:49 PM, Marek Vasut wrote:
On 3/20/25 11:23 AM, Christoph Niedermaier wrote:
If tiny printf is used with 0x%08X (upper case X) the output is
always 0x00000000. It could be confusing if upper case instead
of lower case is used intentionally or accidentally because the
actual value is not output. To avoid this confusion, tiny printf
is extended to support also the formatting with %X.
Signed-off-by: Christoph Niedermaier <cniederma...@dh-electronics.com>
TINY_PRINTF is meant to be tiny, i.e. not consume a lot of space, at
the expense of functionality. This is meant to be used in size
constrained environments, like the SPL. If you need full vsprintf()
formatting support, disable TINY_PRINTF in your config and use the
regular vsprintf() implementation.
The issue is that disabling TINY_PRINTF may not be possible (size
constraints) and some code is compiled for different stages and people
typically don't check whether the format used in printf is valid with
tiny_printf. I've had this issue already in the past, I vaguely recall
"complaining" about it on IRC.
Maybe there's something we can do to verify that the code is working how
we expect it to work, regardless of tiny_printf/full printf selection?
checkpatch or a compile-time check for the formats maybe?
But yeah, essentially the whole thing is... if we continue like this,
we'll just end up getting closer and closer to the full printf which is
not something we want :)
Shall we maybe patch tiny printf to print '?' on unsupported formatting
characters, or outright complain that users should fix their code ?
For the %x/%X thing, we could technically fall back from %X to %x ,
which would do the printing with minimum footprint increase, albeit
slightly malformed:
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 0503c17341f..48db7b1f78f 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -284,6 +284,7 @@ static int _vprintf(struct printf_info *info, const
char *fmt, va_list va)
islong = true;
/* no break */
case 'x':
+ case 'X':
if (islong) {
num = va_arg(va, unsigned long);
div = 1UL << (sizeof(long) * 8
- 4);