>From 4e0eb8f5e31ed9c244113859642b984aaa41c241 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 3 Dec 2026 13:21:09 -0500 Subject: [PATCH] wprintf: fix non-functional %p format specifier the logic to pass thru to byte-based printf wrongly passed the pointer value as a uintmax_t object and applied a 'j' size prefix to %p. this was not valid. in order to avoid duplicating the formatting logic/policy for pointers in the wide printf core, add a separate case to properly pass it as a pointer, and suppress the 'j' prefix. --- src/stdio/vfwprintf.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/stdio/vfwprintf.c b/src/stdio/vfwprintf.c index f6363cfb..48417487 100644 --- a/src/stdio/vfwprintf.c +++ b/src/stdio/vfwprintf.c @@ -146,7 +146,7 @@ static int getint(wchar_t **s) { static const char sizeprefix['y'-'a'] = { ['a'-'a']='L', ['e'-'a']='L', ['f'-'a']='L', ['g'-'a']='L', ['d'-'a']='j', ['i'-'a']='j', ['o'-'a']='j', ['u'-'a']='j', ['x'-'a']='j', -['p'-'a']='j' +['p'-'a']=0 }; static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_arg, int *nl_type) @@ -312,21 +312,24 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_ } if (xp && p<0) goto overflow; - snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%c%c", + snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%s%c", "#"+!(fl & ALT_FORM), "+"+!(fl & MARK_POS), "-"+!(fl & LEFT_ADJ), " "+!(fl & PAD_POS), "0"+!(fl & ZERO_PAD), - sizeprefix[(t|32)-'a'], t); + (char[2]){sizeprefix[(t|32)-'a']}, t); switch (t|32) { case 'a': case 'e': case 'f': case 'g': l = fprintf(f, charfmt, w, p, arg.f); break; - case 'd': case 'i': case 'o': case 'u': case 'x': case 'p': + case 'd': case 'i': case 'o': case 'u': case 'x': l = fprintf(f, charfmt, w, p, arg.i); break; + case 'p': + l = fprintf(f, charfmt, w, p, (void *)(uintptr_t)arg.i); + break; } } -- 2.21.0