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>
Mon, 14 Apr 2025 23:09:20 +0000 (01:09 +0200)
* lib/vasnprintf.c (VASNPRINTF): In the prec_ourselves code, treat a 0b
prefix like a 0x prefix.

ChangeLog
lib/vasnprintf.c

index 1b0508f32e456924f709a91d5451e99617a7b177..6e4e2bbe21590a41d8a0d6bc287cb1314a928230 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-08  Bruno Haible  <bruno@clisp.org>
 
        stddef-h: Make a configure test work with upcoming GCC 15.
index 6ae95ca5dd22f666481e6e967a79b30a91123fb2..a0eab63f472d07495a56cfb5fdb14a6c808565e6 100644 (file)
@@ -1,5 +1,5 @@
 /* vsprintf with automatic memory allocation.
-   Copyright (C) 1999, 2002-2024 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002-2025 Free Software Foundation, Inc.
 
    This file is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as
@@ -6870,10 +6870,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;