When building a testdir of vasnprintf-posix, configured on glibc with the command
gl_cv_func_printf_precision=no gl_cv_func_printf_enomem=no ./configure I get this test failure: test-vasnprintf-posix.c:4583: assertion 'strcmp (result, "0b00000011000000111001 33") == 0' failed Aborted (core dumped) This patch fixes it. 2025-04-10 Bruno Haible <br...@clisp.org> vasnprintf: Fix handling of # flag in %b, %B directives. * lib/vasnprintf.c (VASNPRINTF): In the prec_ourselves code, treat a 0b prefix like a 0x prefix. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index e7db39c74c..a07c1377dd 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -6876,10 +6876,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, || *prec_ptr == ' ')) prefix_count = 1; /* Put the additional zeroes after the 0x prefix if - (flags & FLAG_ALT) || (dp->conversion == 'p'). */ + (flags & FLAG_ALT) || (dp->conversion == 'p'), or + after the 0b prefix if (flags & FLAG_ALT). */ else if (count >= 2 && prec_ptr[0] == '0' - && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) + && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X' + || prec_ptr[1] == 'b' + || prec_ptr[1] == 'B')) prefix_count = 2; move = count - prefix_count;