From ee18e584bfe2c694fdd27bd1251ac5b247f864d5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 18 Aug 2024 13:53:39 -0400 Subject: [PATCH] printf core: replace if(0) blocks around switch cases with explicit gotos this is purely a readability change, not a functional one. all of the integer format cases use a common tail for handling precision logic after the string representation of the number has been generated. the code as I originally wrote it was overly clever in the aim of making a point that the flow could be done without goto, and jumped over intervening cases by wrapping them in if (0) { }, with the case labels for each inside the conditional block scope. this has been a perpetual source of complaints about the readability and comprehensibility of the file, so I am now changing it to explicitly jump to the tail logic with goto statements. --- src/stdio/vfprintf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index 360d723a..3c450c3a 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -557,11 +557,11 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, case 'x': case 'X': a = fmt_x(arg.i, z, t&32); if (arg.i && (fl & ALT_FORM)) prefix+=(t>>4), pl=2; - if (0) { + goto ifmt_tail; case 'o': a = fmt_o(arg.i, z); if ((fl&ALT_FORM) && pINTMAX_MAX) { @@ -573,7 +573,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, } else pl=0; case 'u': a = fmt_u(arg.i, z); - } + ifmt_tail: if (xp && p<0) goto overflow; if (xp) fl &= ~ZERO_PAD; if (!arg.i && !p) {