X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fvfprintf.c;h=31c3d5ddca8f78fc5f8dedf3e6801ab2688433d9;hb=6739b13a172aad9c01572c04cadacc99c7041811;hp=b5948bd2649677f1c0acfd4e292d9f8dec9484d0;hpb=49b3a0d2cedd3693d77924fdc0a7719a75bd28da;p=musl diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index b5948bd2..31c3d5dd 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -207,7 +207,8 @@ typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double) static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) { - uint32_t big[(LDBL_MAX_EXP+LDBL_MANT_DIG)/9+1]; + uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion + + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion uint32_t *a, *d, *r, *z; int e2=0, e, i, j, l; char buf[9+LDBL_MANT_DIG/4], *s; @@ -313,7 +314,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) } while (e2<0) { uint32_t carry=0, *b; - int sh=MIN(9,-e2); + int sh=MIN(9,-e2), need=1+(p+LDBL_MANT_DIG/3+8)/9; for (d=a; d>sh) + carry; @@ -323,7 +324,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) if (carry) *z++ = carry; /* Avoid (slow!) computation past requested precision */ b = (t|32)=='f' ? r : a; - if (z-b > 2+p/9) z = b+2+p/9; + if (z-b > need) z = b+need; e2+=sh; }