Skip to contentSkip to conversation

tiny-printf: Improve %X formatting

PATCH In review Christoph Niedermaier 3 participants 4 messages Mar 20, 2025 – Apr 10, 2025 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tiny-printf: Improve %X formatting

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, treat output of %X as %x. As a compromise for tiny printf, the hex value is then output correctly, but in lower case. This is done to keep it tiny printf small.

---
Cc: Marek Vasut <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Benedikt Spranger <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: John Ogness <[email protected]>
Cc: Jerome Forissier <[email protected]>
Cc: Ilias Apalodimas <[email protected]>

---
 lib/tiny-printf.c | 1 +
 1 file changed, 1 insertion(+)
lib/tiny-printf.c +1 -0
index 0503c17341f..48db7b1f78f 100644
@@ -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);
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Christoph Niedermaier

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, treat output of %X as %x. As a compromise for tiny printf, the hex value is then output correctly, but in lower case. This is done to keep it tiny printf small.

Signature · 1 line
Tom
Reviewed-by on v2 1/1
#2 lore raw
In reply to Christoph Niedermaier
Quoted 9 lines · Christoph Niedermaier

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, treat output of %X as %x. As a compromise for tiny printf, the hex value is then output correctly, but in lower case. This is done to keep it tiny printf small.

#3 lore raw
In reply to Christoph Niedermaier
Quoted 9 lines · Christoph Niedermaier

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, treat output of %X as %x. As a compromise for tiny printf, the hex value is then output correctly, but in lower case. This is done to keep it tiny printf small.

[...]

Applied to u-boot/master, thanks!

[1/1] tiny-printf: Improve %X formatting

      commit: 51b8679b94ea22ffb91925cf56df1950fd4b0e12
Signature · 1 line
Tom