Message ID | 20250320190147.1050427-1-cniedermaier@dh-electronics.com |
---|---|
State | Accepted |
Commit | 51b8679b94ea22ffb91925cf56df1950fd4b0e12 |
Delegated to: | Tom Rini |
Headers | show |
Series | [V2] tiny-printf: Improve %X formatting | expand |
On Thu, Mar 20, 2025 at 08:01:47PM +0100, 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, 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. > > Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com> Reviewed-by: Tom Rini <trini@konsulko.com>
On 3/20/25 8:01 PM, 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, 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. > > Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com> Reviewed-by: Marek Vasut <marex@denx.de>
On Thu, 20 Mar 2025 20:01:47 +0100, 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, 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
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);
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. Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com> --- Cc: Marek Vasut <marex@denx.de> Cc: Tom Rini <trini@konsulko.com> Cc: Benedikt Spranger <b.spranger@linutronix.de> Cc: Simon Glass <sjg@chromium.org> Cc: John Ogness <john.ogness@linutronix.de> Cc: Jerome Forissier <jerome.forissier@linaro.org> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org> --- lib/tiny-printf.c | 1 + 1 file changed, 1 insertion(+)