X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fvfprintf.c;h=9b961e7f7f7972d07e668010786ff4ec9425d6ae;hb=074932c84d34273821e3bfc2511e60a5ce78b8d8;hp=8c81efc2aafd9bc9acf4ae98176189f6857c7c85;hpb=58e2396a9aa23c132faf4198ca4d779c84955b38;p=musl diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index 8c81efc2..9b961e7f 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -107,8 +108,6 @@ union arg static void pop_arg(union arg *arg, int type, va_list *ap) { - /* Give the compiler a hint for optimizing the switch. */ - if ((unsigned)type > MAXSTATE) return; switch (type) { case PTR: arg->p = va_arg(*ap, void *); break; case INT: arg->i = va_arg(*ap, int); @@ -222,6 +221,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) else re=LDBL_MANT_DIG/4-1-p; if (re) { + round *= 1<<(LDBL_MANT_DIG%4); while (re--) round*=16; if (*prefix=='-') { y=-y; @@ -561,7 +561,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, if (0) { case 'o': a = fmt_o(arg.i, z); - if ((fl&ALT_FORM) && p=0) fl &= ~ZERO_PAD; + if (xp) fl &= ~ZERO_PAD; if (!arg.i && !p) { a=z; break; @@ -675,11 +675,12 @@ int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) if (f->mode < 1) f->flags &= ~F_ERR; if (!f->buf_size) { saved_buf = f->buf; - f->wpos = f->wbase = f->buf = internal_buf; + f->buf = internal_buf; f->buf_size = sizeof internal_buf; - f->wend = internal_buf + sizeof internal_buf; + f->wpos = f->wbase = f->wend = 0; } - ret = printf_core(f, fmt, &ap2, nl_arg, nl_type); + if (!f->wend && __towrite(f)) ret = -1; + else ret = printf_core(f, fmt, &ap2, nl_arg, nl_type); if (saved_buf) { f->write(f, 0, 0); if (!f->wpos) ret = -1;