提交 b6e1fe0d 编写于 作者: J Julien Ramseier 提交者: Rich Felker

fix strptime output for %C without %y

in this case, a potentially-uninitialized or unrelated existing value
in tm_year was being used. instead use 0 if %y was not present.
上级 834ef7af
...@@ -11,7 +11,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri ...@@ -11,7 +11,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
int i, w, neg, adj, min, range, *dest, dummy; int i, w, neg, adj, min, range, *dest, dummy;
const char *ex; const char *ex;
size_t len; size_t len;
int want_century = 0, century = 0; int want_century = 0, century = 0, relyear = 0;
while (*f) { while (*f) {
if (*f != '%') { if (*f != '%') {
if (isspace(*f)) for (; *s && isspace(*s); s++); if (isspace(*f)) for (; *s && isspace(*s); s++);
...@@ -144,7 +144,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri ...@@ -144,7 +144,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
if (!s) return 0; if (!s) return 0;
break; break;
case 'y': case 'y':
dest = &tm->tm_year; dest = &relyear;
w = 2; w = 2;
want_century |= 1; want_century |= 1;
goto numeric_digits; goto numeric_digits;
...@@ -198,6 +198,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri ...@@ -198,6 +198,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
} }
} }
if (want_century) { if (want_century) {
tm->tm_year = relyear;
if (want_century & 2) tm->tm_year += century * 100 - 1900; if (want_century & 2) tm->tm_year += century * 100 - 1900;
else if (tm->tm_year <= 68) tm->tm_year += 100; else if (tm->tm_year <= 68) tm->tm_year += 100;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册