@@ -2241,13 +2241,15 @@ char *p = str + strlen(str) - 1; char *end = str - 1; int c; - for (c = *p; p != end; p--, c = *p) { + while (p != end) { + c = *p; if (strchr(trimchars, c) == 0) { end = p; break; } + p--; } p[1] = 0; } @@ -2372,13 +2374,8 @@ case 'f': /* float */ break; /* non-terminals */ - case '0': /* zero pad */ - zpad = 1; - fmt++; fmtLen--; - goto next_fmt; - break; case '+': forceplus = 1; fmt++; fmtLen--; goto next_fmt; @@ -2402,8 +2399,17 @@ inprec = 1; fmt++; fmtLen--; goto next_fmt; break; + case '0': + if (!inprec) { + /* zero pad */ + zpad = 1; + fmt++; fmtLen--; + goto next_fmt; + break; + } + /* fall through */ case '1': case '2': case '3': case '4':