]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf: Fix handling of # flag in %b, %B directives.
authorBruno Haible <bruno@clisp.org>
Thu, 10 Apr 2025 08:42:12 +0000 (10:42 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 10 Apr 2025 08:42:12 +0000 (10:42 +0200)
* lib/vasnprintf.c (VASNPRINTF): In the prec_ourselves code, treat a 0b
prefix like a 0x prefix.

ChangeLog
lib/vasnprintf.c

index 6e9ffa2a4881cdab812bdce02d00a861924ab410..f039a336e87539a774c3672d9cae341611311712 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-04-10  Bruno Haible  <bruno@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.
+
 2025-04-09  Simon Josefsson  <simon@josefsson.org>
 
        string-h: Fix build error on Windows/macOS about strerror_l.
index e7db39c74cf7de111ca6178a351e935d7e353308..a07c1377dd7c092877e776b0c9171013651a8dd6 100644 (file)
@@ -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;