git: 658c3d5376f6 - stable/14 - stdio: Fix error case for positional %wN / %wfN

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Fri, 20 Nov 2026 12:04:53 UTC
The branch stable/14 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=658c3d5376f691604ae5f9ee8c8d788839b6c1fa

commit 658c3d5376f691604ae5f9ee8c8d788839b6c1fa
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-16 11:45:15 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-20 12:04:06 +0000

    stdio: Fix error case for positional %wN / %wfN
    
    In the case were N was not a valid bit width, we were taking the wrong
    error path.
    
    Fixes:          5e809bf1c93f ("stdio: Fix positional %wN / %wfN conversion")
    (cherry picked from commit 0bf5d86620d047b4551d7414bf8011a328264b3d)
---
 lib/libc/stdio/printf-pos.c          | 4 ++--
 lib/libc/tests/stdio/snprintf_test.c | 2 ++
 lib/libc/tests/stdio/swprintf_test.c | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/libc/stdio/printf-pos.c b/lib/libc/stdio/printf-pos.c
index 47fd30578e32..a4c59c6ac847 100644
--- a/lib/libc/stdio/printf-pos.c
+++ b/lib/libc/stdio/printf-pos.c
@@ -373,7 +373,7 @@ reswitch:	switch (ch) {
 					flags &= ~FASTINT;
 					fmt--;
 				}
-				goto error;
+				break;
 			}
 			goto rflag;
 		case 'z':
@@ -606,7 +606,7 @@ reswitch:	switch (ch) {
 					flags &= ~FASTINT;
 					fmt--;
 				}
-				goto error;
+				break;
 			}
 			goto rflag;
 		case 'z':
diff --git a/lib/libc/tests/stdio/snprintf_test.c b/lib/libc/tests/stdio/snprintf_test.c
index b805f513c402..392fb43f9795 100644
--- a/lib/libc/tests/stdio/snprintf_test.c
+++ b/lib/libc/tests/stdio/snprintf_test.c
@@ -175,6 +175,7 @@ ATF_TC_BODY(snprintf_wN, tc)
 	SNPRINTF_TEST(" 1", "%1$*2$w16d", (int16_t)1, 2);
 	SNPRINTF_TEST(" 1", "%1$*2$w32d", (int32_t)1, 2);
 	SNPRINTF_TEST(" 1", "%1$*2$w64d", (int64_t)1, 2);
+	SNPRINTF_TEST("42w42d", "%1$d%w42d", 42);
 }
 
 ATF_TC_WITHOUT_HEAD(snprintf_wfN);
@@ -211,6 +212,7 @@ ATF_TC_BODY(snprintf_wfN, tc)
 	SNPRINTF_TEST(" 1", "%1$*2$w16d", (int_fast16_t)1, 2);
 	SNPRINTF_TEST(" 1", "%1$*2$w32d", (int_fast32_t)1, 2);
 	SNPRINTF_TEST(" 1", "%1$*2$w64d", (int_fast64_t)1, 2);
+	SNPRINTF_TEST("42wf42d", "%1$d%wf42d", 42);
 }
 
 ATF_TP_ADD_TCS(tp)
diff --git a/lib/libc/tests/stdio/swprintf_test.c b/lib/libc/tests/stdio/swprintf_test.c
index 6f3d56657f4c..6a9e68c9d5fd 100644
--- a/lib/libc/tests/stdio/swprintf_test.c
+++ b/lib/libc/tests/stdio/swprintf_test.c
@@ -176,6 +176,7 @@ ATF_TC_BODY(swprintf_wN, tc)
 	SWPRINTF_TEST(" 1", "%1$*2$w16d", (int16_t)1, 2);
 	SWPRINTF_TEST(" 1", "%1$*2$w32d", (int32_t)1, 2);
 	SWPRINTF_TEST(" 1", "%1$*2$w64d", (int64_t)1, 2);
+	SWPRINTF_TEST("42w42d", "%1$d%w42d", 42);
 }
 
 ATF_TC_WITHOUT_HEAD(swprintf_wfN);
@@ -212,6 +213,7 @@ ATF_TC_BODY(swprintf_wfN, tc)
 	SWPRINTF_TEST(" 1", "%1$*2$w16d", (int_fast16_t)1, 2);
 	SWPRINTF_TEST(" 1", "%1$*2$w32d", (int_fast32_t)1, 2);
 	SWPRINTF_TEST(" 1", "%1$*2$w64d", (int_fast64_t)1, 2);
+	SWPRINTF_TEST("42wf42d", "%1$d%wf42d", 42);
 }
 
 ATF_TP_ADD_TCS(tp)