git: 0e3fce268ade - main - stdio: Fix positional %B / %b conversion
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 15 Nov 2026 17:17:42 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=0e3fce268adeec8f4c87b99759dae6a592b3d365
commit 0e3fce268adeec8f4c87b99759dae6a592b3d365
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-15 16:35:28 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-15 17:16:55 +0000
stdio: Fix positional %B / %b conversion
MFC after: 1 week
Fixes: d9dc1603d6e4 ("libc: Implement N2630.")
Fixes: b9385720f34b ("libc: Add unit tests for N2630 and possible collateral damage.")
---
lib/libc/stdio/printf-pos.c | 10 ++++++++++
lib/libc/tests/stdio/snprintf_test.c | 2 ++
lib/libc/tests/stdio/swprintf_test.c | 2 ++
3 files changed, 14 insertions(+)
diff --git a/lib/libc/stdio/printf-pos.c b/lib/libc/stdio/printf-pos.c
index 07b518c59214..27b59f25b67d 100644
--- a/lib/libc/stdio/printf-pos.c
+++ b/lib/libc/stdio/printf-pos.c
@@ -340,6 +340,11 @@ reswitch: switch (ch) {
case 'z':
flags |= SIZET;
goto rflag;
+ case 'B':
+ case 'b':
+ if ((error = adduarg(&types, flags)))
+ goto error;
+ break;
case 'C':
flags |= LONGINT;
/*FALLTHROUGH*/
@@ -530,6 +535,11 @@ reswitch: switch (ch) {
case 'z':
flags |= SIZET;
goto rflag;
+ case 'B':
+ case 'b':
+ if ((error = adduarg(&types, flags)))
+ goto error;
+ break;
case 'C':
flags |= LONGINT;
/*FALLTHROUGH*/
diff --git a/lib/libc/tests/stdio/snprintf_test.c b/lib/libc/tests/stdio/snprintf_test.c
index c8f04b7e5524..d5f056b9542d 100644
--- a/lib/libc/tests/stdio/snprintf_test.c
+++ b/lib/libc/tests/stdio/snprintf_test.c
@@ -46,6 +46,7 @@ ATF_TC_BODY(snprintf_b, tc)
SNPRINTF_TEST(" 0b1", "%#12b", 1);
SNPRINTF_TEST("0b0000000001", "%#012b", 1);
SNPRINTF_TEST("0b1111111111111111111111111111111", "%#b", INT_MAX);
+ SNPRINTF_TEST("0b0011", "%1$#05jb%b", (uintmax_t)1, 1);
}
ATF_TC_WITHOUT_HEAD(snprintf_B);
@@ -65,6 +66,7 @@ ATF_TC_BODY(snprintf_B, tc)
SNPRINTF_TEST(" 0B1", "%#12B", 1);
SNPRINTF_TEST("0B0000000001", "%#012B", 1);
SNPRINTF_TEST("0B1111111111111111111111111111111", "%#B", INT_MAX);
+ SNPRINTF_TEST("0B0011", "%1$#05jB%B", (uintmax_t)1, 1);
}
ATF_TC_WITHOUT_HEAD(snprintf_d);
diff --git a/lib/libc/tests/stdio/swprintf_test.c b/lib/libc/tests/stdio/swprintf_test.c
index fe2957928344..5d9c60fb9ee7 100644
--- a/lib/libc/tests/stdio/swprintf_test.c
+++ b/lib/libc/tests/stdio/swprintf_test.c
@@ -47,6 +47,7 @@ ATF_TC_BODY(swprintf_b, tc)
SWPRINTF_TEST(" 0b1", "%#12b", 1);
SWPRINTF_TEST("0b0000000001", "%#012b", 1);
SWPRINTF_TEST("0b1111111111111111111111111111111", "%#b", INT_MAX);
+ SWPRINTF_TEST("0b0011", "%1$#05jb%b", (uintmax_t)1, 1);
}
ATF_TC_WITHOUT_HEAD(swprintf_B);
@@ -66,6 +67,7 @@ ATF_TC_BODY(swprintf_B, tc)
SWPRINTF_TEST(" 0B1", "%#12B", 1);
SWPRINTF_TEST("0B0000000001", "%#012B", 1);
SWPRINTF_TEST("0B1111111111111111111111111111111", "%#B", INT_MAX);
+ SWPRINTF_TEST("0B0011", "%1$#05jB%B", (uintmax_t)1, 1);
}
ATF_TC_WITHOUT_HEAD(swprintf_d);