From d90fab3f2bc66e7666d55f8794c387124eaf02bb Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Fri, 21 Aug 2026 12:48:01 -0400 Subject: [PATCH] Fix alternate form flag for %x testing stale signed value The alternate-form branch for %x/%X gated the "0x" prefix on i_num, which is only ever assigned by the signed/unsigned decimal conversions. A standalone "%#x" with a nonzero value therefore printed no prefix (i_num still held its zero initializer), while "%d %#x" consumed the earlier conversion's value and could print a prefix for zero. Test the unsigned conversion result ui_num instead, matching the "0" check the octal case already performs on the converted digits. --- main/snprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/snprintf.c b/main/snprintf.c index 78aa6cc3a8db..11b58e74e16e 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -830,7 +830,7 @@ static size_t format_converter(buffy * odp, const char *fmt, va_list ap) /* {{{ } s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); - if (alternate_form && i_num != 0) { + if (alternate_form && ui_num != 0) { *--s = *fmt; /* 'x' or 'X' */ *--s = '0'; s_len += 2;