aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0001-fix-strftime-y-for-negative-years.patch
blob: 85d21c7e3f055dee8a33d14c989406c083d26619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
From 61fb81e3959ecf0848eef8d2767bb80ae5d1a68e Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Mon, 2 Jan 2017 17:30:40 -0500
Subject: [PATCH 1/2] fix strftime %y for negative years

commit 583ea83541dcc6481c7a1bd1a9b485526bad84a1 fixed the case where
tm_year is negative but the resulting year (offset by 1900) was still
positive, which is always the case for time_t values that fit in 32
bits, but not for arbitrary inputs.

based on an earlier patch by Julien Ramseier which was overlooked at
the time the previous fix was applied.
---
 src/time/strftime.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/time/strftime.c b/src/time/strftime.c
index e103e02b7204..a30392044bf8 100644
--- a/src/time/strftime.c
+++ b/src/time/strftime.c
@@ -166,8 +166,8 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *
 		item = T_FMT;
 		goto nl_strftime;
 	case 'y':
-		val = tm->tm_year % 100;
-		if (val<0) val += 100;
+		val = (tm->tm_year + 1900LL) % 100;
+		if (val < 0) val = -val;
 		goto number;
 	case 'Y':
 		val = tm->tm_year + 1900LL;
-- 
2.8.3