fix strftime field widths with %F format and zero year
authorRich Felker <dalias@aerifal.cx>
Mon, 5 Feb 2018 18:36:04 +0000 (13:36 -0500)
committerRich Felker <dalias@aerifal.cx>
Mon, 5 Feb 2018 18:38:21 +0000 (13:38 -0500)
the code to strip initial sign and leading zeros inadvertently
stripped all the zeros and the subsequent '-' separating the month.
instead, only strip sign characters from the very first position, and
only strip zeros when they are followed by another digit.

based on testing by Dennis Wölfing.

src/time/strftime.c

index d1ca7cae99429536a53901aab554cbda72776210..16b3bb21635d6ae801e4bae2e9fbdce343bfee7b 100644 (file)
@@ -251,7 +251,8 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st
                t = __strftime_fmt_1(&buf, &k, *f, tm, loc, pad);
                if (!t) break;
                if (width) {
-                       for (; *t=='+' || *t=='-' || (*t=='0'&&t[1]); t++, k--);
+                       if (*t=='+' || *t=='-') t++, k--;
+                       for (; *t=='0' && t[1]-'0'<10U; t++, k--);
                        width--;
                        if (plus && tm->tm_year >= 10000-1900)
                                s[l++] = '+';