Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Mon, 25 Jul 2016 21:56:25 +0200
From: Julien Ramseier <j.ramseier@...il.com>
To: musl@...ts.openwall.com
Subject: [PATCH] strftime: fix %y format

The following patch fixes the '%y' format in strftime/wcsftime
when using negative tm_year values.

Results:

tm_year    year     before   after
-----------------------------------------
-2901     -1001       "-1"    "01"
-2900     -1000       "00"    "00"
-2899      -999      "-99"    "99"

 -901       999       "-1"    "99"
 -900      1000       "00"    "00"
 -899      1001      "-99"    "01"

   -1      1899       "-1"    "99"
    0      1900       "00"    "00"
    1      1901       "01"    "01"

---
 src/time/strftime.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/time/strftime.c b/src/time/strftime.c
index f1ccc4d..a303920 100644
--- a/src/time/strftime.c
+++ b/src/time/strftime.c
@@ -166,7 +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;
+		val = (tm->tm_year + 1900LL) % 100;
+		if (val < 0) val = -val;
 		goto number;
 	case 'Y':
 		val = tm->tm_year + 1900LL;
--
2.9.2

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.