author | Rich Felker <dalias@aerifal.cx> | 2024年08月26日 16:01:11 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2024年08月26日 16:01:11 -0400 |
commit | 572a2e2eb91f00f2f25d301cfb50f435e7ae16b3 (patch) | |
tree | 08c826277b16d6e70b983f9e9b8cc103eeec23d1 /src | |
parent | c94a0c16f08894ce3be6dafb0fe80baa77a6ff2a (diff) | |
download | musl-572a2e2eb91f00f2f25d301cfb50f435e7ae16b3.tar.gz |
-rw-r--r-- | src/stdio/vfprintf.c | 12 |
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index 3c450c3a..76733997 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -178,10 +178,14 @@ static char *fmt_u(uintmax_t x, char *s) typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)]; #endif -static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) +static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t, int ps) { - uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion - + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion + int bufsize = (ps==BIGLPRE) + ? (LDBL_MANT_DIG+28)/29 + 1 + // mantissa expansion + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9 // exponent expansion + : (DBL_MANT_DIG+28)/29 + 1 + + (DBL_MAX_EXP+DBL_MANT_DIG+28+8)/9; + uint32_t big[bufsize]; uint32_t *a, *d, *r, *z; int e2=0, e, i, j, l; char buf[9+LDBL_MANT_DIG/4], *s; @@ -618,7 +622,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, case 'e': case 'f': case 'g': case 'a': case 'E': case 'F': case 'G': case 'A': if (xp && p<0) goto overflow; - l = fmt_fp(f, arg.f, w, p, fl, t); + l = fmt_fp(f, arg.f, w, p, fl, t, ps); if (l<0) goto overflow; continue; } |