about summary refs log tree commit diff
path: root/src/time
diff options
context:
space:
mode:
authorJulien Ramseier <j.ramseier@gmail.com>2017-03-21 12:35:16 -0400
committerRich Felker <dalias@aerifal.cx>2017-03-21 12:35:16 -0400
commitb6e1fe0d5e78dac647e85d49c2d537bb071ba49e (patch)
tree6f9a689e136efb6a152436c0975e857be7f4f135 /src/time
parent834ef7aff5695e79b1feeacfdc15eaba6a42cab9 (diff)
downloadmusl-b6e1fe0d5e78dac647e85d49c2d537bb071ba49e.tar.gz
musl-b6e1fe0d5e78dac647e85d49c2d537bb071ba49e.tar.xz
musl-b6e1fe0d5e78dac647e85d49c2d537bb071ba49e.zip
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.
Diffstat (limited to 'src/time')
-rw-r--r--src/time/strptime.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/time/strptime.c b/src/time/strptime.c
index cff0a7c1..c54a0d8c 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -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;
 	const char *ex;
 	size_t len;
-	int want_century = 0, century = 0;
+	int want_century = 0, century = 0, relyear = 0;
 	while (*f) {
 		if (*f != '%') {
 			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
 			if (!s) return 0;
 			break;
 		case 'y':
-			dest = &tm->tm_year;
+			dest = &relyear;
 			w = 2;
 			want_century |= 1;
 			goto numeric_digits;
@@ -198,6 +198,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
 		}
 	}
 	if (want_century) {
+		tm->tm_year = relyear;
 		if (want_century & 2) tm->tm_year += century * 100 - 1900;
 		else if (tm->tm_year <= 68) tm->tm_year += 100;
 	}