aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-03-28 13:22:27 -0500
committerRob Landley <rob@landley.net>2015-03-28 13:22:27 -0500
commit5d431d1e1f9172587775c00a07b767f9b544cb91 (patch)
tree8988850978ee50e0ce6ca7b2527e096740514cdd /toys
parent58e06423be7f568076d273a358975317c14de30a (diff)
downloadtoybox-5d431d1e1f9172587775c00a07b767f9b544cb91.tar.gz
Fix printf bug (%.s should be %.0s not %s) reported by Isabella Parakiss.
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/printf.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/toys/posix/printf.c b/toys/posix/printf.c
index 4c9de286..30ae931d 100644
--- a/toys/posix/printf.c
+++ b/toys/posix/printf.c
@@ -91,19 +91,17 @@ void printf_main(void)
// Handle %escape
else {
char c, *end = 0, *aa, *to = toybuf;
- int wp[] = {0,-1}, i;
+ int wp[] = {0,-1}, i = 0;
// Parse width.precision between % and type indicator.
*to++ = '%';
while (strchr("-+# '0", *f) && (to-toybuf)<10) *to++ = *f++;
- for (i=0; i<2; i++) {
+ for (;;) {
if (eat(&f, '*')) {
if (*arg) wp[i] = atolx(*arg++);
- } else while (*f >= '0' && *f <= '9') {
- if (wp[i]<0) wp[i] = 0;
- wp[i] = (wp[i]*10)+(*f++)-'0';
- }
- if (!eat(&f, '.')) break;
+ } else while (*f >= '0' && *f <= '9') wp[i] = (wp[i]*10)+(*f++)-'0';
+ if (i++ || !eat(&f, '.')) break;
+ wp[1] = 0;
}
c = *f++;
seen = sprintf(to, "*.*%c", c);;