printf core: fix gratuitous integer formatting buffer size
authorRich Felker <dalias@aerifal.cx>
Tue, 13 Jun 2023 00:04:22 +0000 (20:04 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 13 Jun 2023 00:04:22 +0000 (20:04 -0400)
the extra terms 3 and LDBL_MANT_DIG/4 are remnants of a proto-musl
implementation of printf where the sign/prefix and floating point
conversions were performed naively into this buffer. having them there
obscures the actual intended buffer size (sufficient to hold between 2
and 3 octal digits per byte, rounded up to 3 for simplicity) and
interferes with upcoming work to add C2x binary formats which would
otherwise be stuck having to explain a similar fix to buffer size as
part of an unrelated change.

src/stdio/vfprintf.c

index c551ccf..33019ff 100644 (file)
@@ -437,7 +437,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
        unsigned st, ps;
        int cnt=0, l=0;
        size_t i;
-       char buf[sizeof(uintmax_t)*3+3+LDBL_MANT_DIG/4];
+       char buf[sizeof(uintmax_t)*3];
        const char *prefix;
        int t, pl;
        wchar_t wc[2], *ws;