Re: [PATCH v2 next 08/11] tools/nolibc/printf: Add support for zero padding and field precision
From: Willy Tarreau
Date: Sun Feb 08 2026 - 11:16:33 EST
On Fri, Feb 06, 2026 at 07:11:18PM +0000, david.laight.linux@xxxxxxxxx wrote:
> + /* Add zero padding */
> + if (_NOLIBC_PF_FLAGS_CONTAIN(flags, '0', '.')) {
> + if (!_NOLIBC_PF_FLAGS_CONTAIN(flags, '.')) {
> + if (_NOLIBC_PF_FLAGS_CONTAIN(flags, '-'))
> + /* Left justify overrides zero pad */
> + goto prepend_sign;
> + /* eg "%05d", Zero pad to field width less sign */
> + precision = width;
> + if (sign) {
> + precision--;
> + if (sign >= 256)
This is the one that confused me with previous patch. As long as we cannot
have 4 chars that's OK, otherwise the 4th char can flip the sign. We could
also add and unsigned cast here to clarify this, though admittedly this
should not change over time.
Just for the record, this is the patch that increases the code the most
(+265 bytes for me, no jump tables). But I think the feature is worth it
and I'm not seeing low hanging fruits to reduce it. I honestly find the
code particularly complex to follow now but that's related to the
multiplicity of output formats and I doubt we can do much about this.
Acked-by: Willy Tarreau <w@xxxxxx>
Willy