From: David Laight Date: Sun, 8 Mar 2026 11:37:30 +0000 (+0000) Subject: tools/nolibc/printf: Output pad characters in 16 byte chunks X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a2fa5a752ce67c11a9d6d6535165195073ce0c46;p=thirdparty%2Fkernel%2Flinux.git tools/nolibc/printf: Output pad characters in 16 byte chunks Simple to do and saves calls to the callback function. Change variables written, width and len to 'signed int' to get better code. Signed-off-by: David Laight Acked-by: Willy Tarreau Link: https://patch.msgid.link/20260308113742.12649-6-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh --- diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 985e7f0834bf1..bdecc703511c2 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -312,8 +312,8 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list { char escape, lpref, ch; unsigned long long v; - unsigned int written, width; - size_t len, ofs; + int written, width, len; + size_t ofs; char outbuf[21]; const char *outstr; @@ -415,10 +415,14 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list outstr = fmt; len = ofs - 1; flush_str: - while (width-- > len) { - if (cb(state, " ", 1) != 0) + width -= len; + while (width > 0) { + /* Output pad in 16 byte blocks with the small block first. */ + int pad_len = ((width - 1) & 15) + 1; + width -= pad_len; + written += pad_len; + if (cb(state, " ", pad_len) != 0) return -1; - written += 1; } if (cb(state, outstr, len) != 0) return -1;