comparison toys/posix/printf.c @ 1767:12fa15de1cd4 draft

Fix printf bug (%.s should be %.0s not %s) reported by Isabella Parakiss.
author Rob Landley <rob@landley.net>
date Sat, 28 Mar 2015 13:22:27 -0500
parents 848969327d77
children
comparison
equal deleted inserted replaced
1766:190ecf70fbe5 1767:12fa15de1cd4
89 else if (!eat(&f, '%') || *f == '%') putchar(*f++); 89 else if (!eat(&f, '%') || *f == '%') putchar(*f++);
90 90
91 // Handle %escape 91 // Handle %escape
92 else { 92 else {
93 char c, *end = 0, *aa, *to = toybuf; 93 char c, *end = 0, *aa, *to = toybuf;
94 int wp[] = {0,-1}, i; 94 int wp[] = {0,-1}, i = 0;
95 95
96 // Parse width.precision between % and type indicator. 96 // Parse width.precision between % and type indicator.
97 *to++ = '%'; 97 *to++ = '%';
98 while (strchr("-+# '0", *f) && (to-toybuf)<10) *to++ = *f++; 98 while (strchr("-+# '0", *f) && (to-toybuf)<10) *to++ = *f++;
99 for (i=0; i<2; i++) { 99 for (;;) {
100 if (eat(&f, '*')) { 100 if (eat(&f, '*')) {
101 if (*arg) wp[i] = atolx(*arg++); 101 if (*arg) wp[i] = atolx(*arg++);
102 } else while (*f >= '0' && *f <= '9') { 102 } else while (*f >= '0' && *f <= '9') wp[i] = (wp[i]*10)+(*f++)-'0';
103 if (wp[i]<0) wp[i] = 0; 103 if (i++ || !eat(&f, '.')) break;
104 wp[i] = (wp[i]*10)+(*f++)-'0'; 104 wp[1] = 0;
105 }
106 if (!eat(&f, '.')) break;
107 } 105 }
108 c = *f++; 106 c = *f++;
109 seen = sprintf(to, "*.*%c", c);; 107 seen = sprintf(to, "*.*%c", c);;
110 errno = 0; 108 errno = 0;
111 aa = *arg ? *arg++ : ""; 109 aa = *arg ? *arg++ : "";