fix padding string formats to width in wide printf variants

the idiom fprintf(f, "%.*s", n, "") was wrongly used in vfwprintf as a
means of producing n spaces; instead it produces no output. the
correct form is fprintf(f, "%*s", n, ""), using width instead of
precision, since for %s the later is a maximum rather than a minimum.
This commit is contained in:
Rich Felker 2016-03-16 16:35:22 -04:00
parent de400b6609
commit 4aac019a0e

View File

@ -288,9 +288,9 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_
z = wmemchr(a, 0, p); z = wmemchr(a, 0, p);
if (z) p=z-a; if (z) p=z-a;
if (w<p) w=p; if (w<p) w=p;
if (!(fl&LEFT_ADJ)) fprintf(f, "%.*s", w-p, ""); if (!(fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
out(f, a, p); out(f, a, p);
if ((fl&LEFT_ADJ)) fprintf(f, "%.*s", w-p, ""); if ((fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
l=w; l=w;
continue; continue;
case 'm': case 'm':
@ -303,14 +303,14 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_
if (i<0) return -1; if (i<0) return -1;
p=l; p=l;
if (w<p) w=p; if (w<p) w=p;
if (!(fl&LEFT_ADJ)) fprintf(f, "%.*s", w-p, ""); if (!(fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
bs = arg.p; bs = arg.p;
while (l--) { while (l--) {
i=mbtowc(&wc, bs, MB_LEN_MAX); i=mbtowc(&wc, bs, MB_LEN_MAX);
bs+=i; bs+=i;
fputwc(wc, f); fputwc(wc, f);
} }
if ((fl&LEFT_ADJ)) fprintf(f, "%.*s", w-p, ""); if ((fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
l=w; l=w;
continue; continue;
} }