X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fvfprintf.c;h=2ecf76925c97f3ee34faf03b3b23a6e5c1c2dc81;hb=7c82870d4543f0eeb0e3a2638b083ff97b41a0fb;hp=0be75498a36ce689ace70e1bd869819acaf10715;hpb=89740868c9f1c84b8ee528468d12df1fa72cd392;p=musl diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index 0be75498..2ecf7692 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -13,8 +13,6 @@ #define MAX(a,b) ((a)>(b) ? (a) : (b)) #define MIN(a,b) ((a)<(b) ? (a) : (b)) -#define CONCAT2(x,y) x ## y -#define CONCAT(x,y) CONCAT2(x,y) /* Convenient bit representation for modifier flags, which all fall * within 31 codepoints of the space character. */ @@ -160,7 +158,7 @@ static void pop_arg(union arg *arg, int type, va_list *ap) static void out(FILE *f, const char *s, size_t l) { - __fwritex((void *)s, l, f); + if (!(f->flags & F_ERR)) __fwritex((void *)s, l, f); } static void pad(FILE *f, char c, int w, int l, int fl) @@ -227,7 +225,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) if (!isfinite(y)) { char *s = (t&32)?"inf":"INF"; - if (y!=y) s=(t&32)?"nan":"NAN", pl=0; + if (y!=y) s=(t&32)?"nan":"NAN"; pad(f, ' ', w, 3+pl, fl&~ZERO_PAD); out(f, prefix, pl); out(f, s, 3); @@ -308,8 +306,8 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) *d = x % 1000000000; carry = x / 1000000000; } - if (!z[-1] && z>a) z--; if (carry) *--a = carry; + while (z>a && !z[-1]) z--; e2-=sh; } while (e2<0) { @@ -343,7 +341,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) x = *d % i; /* Are there any significant digits past j? */ if (x || d+1!=z) { - long double round = CONCAT(0x1p,LDBL_MANT_DIG); + long double round = 2/LDBL_EPSILON; long double small; if (*d/i & 1) round += 2; if (xflags & F_ERR; + if (f->mode < 1) f->flags &= ~F_ERR; if (!f->buf_size) { saved_buf = f->buf; f->wpos = f->wbase = f->buf = internal_buf; @@ -682,6 +683,8 @@ int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) f->buf_size = 0; f->wpos = f->wbase = f->wend = 0; } + if (f->flags & F_ERR) ret = -1; + f->flags |= olderr; FUNLOCK(f); va_end(ap2); return ret;