From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12469 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Dennis_W=c3=b6lfing?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: Bugs in strftime Date: Tue, 6 Feb 2018 21:24:12 +0100 Message-ID: <5c58bd79-59a8-e6fc-c204-31c581f54d0b@gmx.de> References: <52570ac7-4ba2-0c7a-04b8-c1c9727a5509@gmx.de> <20180205175124.GZ1627@brightrain.aerifal.cx> <20180206174618.GB1220@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------469AB21D4E43AC7FE61AB690" X-Trace: blaine.gmane.org 1517948541 8585 195.159.176.226 (6 Feb 2018 20:22:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 6 Feb 2018 20:22:21 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 To: musl@lists.openwall.com Original-X-From: musl-return-12485-gllmg-musl=m.gmane.org@lists.openwall.com Tue Feb 06 21:22:17 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ej9km-0001Oq-1e for gllmg-musl@m.gmane.org; Tue, 06 Feb 2018 21:22:08 +0100 Original-Received: (qmail 17911 invoked by uid 550); 6 Feb 2018 20:24:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17884 invoked from network); 6 Feb 2018 20:24:10 -0000 In-Reply-To: <20180206174618.GB1220@brightrain.aerifal.cx> Content-Language: en-US X-Provags-ID: V03:K0:qwVKgCbtFJzhoVvwgFMwsuaugiTyO1duP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musl.general:12469 Archived-At: This is a multi-part message in MIME format. --------------469AB21D4E43AC7FE61AB690 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 06.02.2018 18:46, Rich Felker wrote: > Attaching a patch I intend to push if I don't find any problems, and > the one I've already got queued up for the %F issue. Let me know if > you see any issues with them. With these two patches applied I no longer see any failures. I have attached the patch for libc-test. The test in the patch now uses the test.h header from libc-test and is now indented by tabs. Otherwise the test is still mostly the same. --------------469AB21D4E43AC7FE61AB690 Content-Type: text/x-patch; name="0001-add-test-for-strftime.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-add-test-for-strftime.patch" >From 11bc9641b443162afb336d7d9635c9ec16c51c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20W=C3=B6lfing?= Date: Tue, 6 Feb 2018 20:54:00 +0100 Subject: [PATCH] add test for strftime --- src/functional/strftime.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/functional/strftime.c diff --git a/src/functional/strftime.c b/src/functional/strftime.c new file mode 100644 index 0000000..25e1172 --- /dev/null +++ b/src/functional/strftime.c @@ -0,0 +1,181 @@ +#include +#include +#include +#include +#include "test.h" + +static char buffer[100]; + +static void checkStrftime(const char* format, const struct tm* tm, + const char* expected) { + size_t resultLength = strftime(buffer, sizeof(buffer), format, tm); + + if (resultLength != 0 && strcmp(buffer, expected) != 0) { + t_error("\"%s\": expected \"%s\", got \"%s\"\n", format, expected, buffer); + } else if (resultLength == 0 && strlen(expected) != 0) { + t_error("\"%s\": expected \"%s\", got nothing\n", format, expected); + } +} + +static struct tm tm1 = { + .tm_sec = 45, + .tm_min = 23, + .tm_hour = 13, + .tm_mday = 3, + .tm_mon = 0, + .tm_year = 2016 - 1900, + .tm_wday = 0, + .tm_yday = 2, + .tm_isdst = 0 +}; + +static struct tm tm2 = { + .tm_sec = 53, + .tm_min = 17, + .tm_hour = 5, + .tm_mday = 5, + .tm_mon = 0, + .tm_year = 10009 - 1900, + .tm_wday = 1, + .tm_yday = 4, + .tm_isdst = 0 +}; + +static struct tm tm3 = { + .tm_sec = 0, + .tm_min = 0, + .tm_hour = 12, + .tm_mday = 23, + .tm_mon = 1, + .tm_year = 0 - 1900, + .tm_wday = 3, + .tm_yday = 53, + .tm_isdst = 0 +}; + +static struct tm tm4 = { + .tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = 0, + .tm_year = -123 - 1900, + .tm_wday = 1, + .tm_yday = 0, + .tm_isdst = 0 +}; + +static struct tm tm5 = { + .tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = 0, + .tm_year = INT_MAX, + .tm_wday = 3, + .tm_yday = 0, + .tm_isdst = 0 +}; + +int main() { + setenv("TZ", "UTC0", 1); + + checkStrftime("%c", &tm1, "Sun Jan 3 13:23:45 2016"); + checkStrftime("%c", &tm2, "Mon Jan 5 05:17:53 +10009"); + checkStrftime("%c", &tm3, "Wed Feb 23 12:00:00 0000"); + + // The POSIX.1-2008 standard does not specify the padding character for + // "%C". The C standard requires that the number is padded by '0'. + // See also http://austingroupbugs.net/view.php?id=1184 + checkStrftime("%C", &tm1, "20"); + checkStrftime("%03C", &tm1, "020"); + checkStrftime("%+3C", &tm1, "+20"); + checkStrftime("%C", &tm2, "100"); + checkStrftime("%C", &tm3, "00"); + checkStrftime("%01C", &tm3, "0"); + + checkStrftime("%F", &tm1, "2016-01-03"); + checkStrftime("%012F", &tm1, "002016-01-03"); + checkStrftime("%+10F", &tm1, "2016-01-03"); + checkStrftime("%+11F", &tm1, "+2016-01-03"); + checkStrftime("%F", &tm2, "+10009-01-05"); + checkStrftime("%011F", &tm2, "10009-01-05"); + checkStrftime("%F", &tm3, "0000-02-23"); + checkStrftime("%01F", &tm3, "0-02-23"); + checkStrftime("%06F", &tm3, "0-02-23"); + checkStrftime("%010F", &tm3, "0000-02-23"); + checkStrftime("%F", &tm4, "-123-01-01"); + checkStrftime("%011F", &tm4, "-0123-01-01"); + + checkStrftime("%g", &tm1, "15"); + checkStrftime("%g", &tm2, "09"); + + checkStrftime("%G", &tm1, "2015"); + checkStrftime("%+5G", &tm1, "+2015"); + checkStrftime("%04G", &tm2, "10009"); + + checkStrftime("%r", &tm1, "01:23:45 PM"); + checkStrftime("%r", &tm2, "05:17:53 AM"); + checkStrftime("%r", &tm3, "12:00:00 PM"); + checkStrftime("%r", &tm4, "12:00:00 AM"); + + // The "%s" specifier was accepted by the Austin Group for the next POSIX.1 + // revision. See http://austingroupbugs.net/view.php?id=169 + checkStrftime("%s", &tm1, "1451827425"); + if (sizeof(time_t) * CHAR_BIT >= 64) { + checkStrftime("%s", &tm2, "253686748673"); + } + + checkStrftime("%T", &tm1, "13:23:45"); + checkStrftime("%T", &tm2, "05:17:53"); + checkStrftime("%T", &tm3, "12:00:00"); + checkStrftime("%T", &tm4, "00:00:00"); + + checkStrftime("%U", &tm1, "01"); + checkStrftime("%U", &tm2, "01"); + checkStrftime("%U", &tm3, "08"); + + checkStrftime("%V", &tm1, "53"); + checkStrftime("%V", &tm2, "02"); + checkStrftime("%V", &tm3, "08"); + + checkStrftime("%W", &tm1, "00"); + checkStrftime("%W", &tm2, "01"); + checkStrftime("%W", &tm3, "08"); + + checkStrftime("%x", &tm1, "01/03/16"); + checkStrftime("%X", &tm1, "13:23:45"); + checkStrftime("%y", &tm1, "16"); + + // There is no standard that explicitly specifies the exact format of "%Y". + // The C standard says that "%F" is equivalent to "%Y-%m-%d". The + // POSIX.1-2008 standard says that "%F" is equivalent to "%+4Y-%m-%d". + // This implies that to conform to both standards "%Y" needs to be + // equivalent to "%+4Y". + // See also http://austingroupbugs.net/view.php?id=739 + checkStrftime("%Y", &tm1, "2016"); + checkStrftime("%05Y", &tm1, "02016"); + checkStrftime("%+4Y", &tm1, "2016"); + checkStrftime("%+5Y", &tm1, "+2016"); + checkStrftime("%Y", &tm2, "+10009"); + checkStrftime("%05Y", &tm2, "10009"); + checkStrftime("%Y", &tm3, "0000"); + checkStrftime("%02Y", &tm3, "00"); + checkStrftime("%+5Y", &tm3, "+0000"); + checkStrftime("%Y", &tm4, "-123"); + checkStrftime("%+4Y", &tm4, "-123"); + checkStrftime("%+5Y", &tm4, "-0123"); + + if (INT_MAX == 0x7FFFFFFF) { + // The standard does not specify any range for tm_year, so INT_MAX + // should be valid. + checkStrftime("%y", &tm5, "47"); + checkStrftime("%Y", &tm5, "+2147485547"); + checkStrftime("%011Y", &tm5, "02147485547"); + if (sizeof(time_t) * CHAR_BIT >= 64) { + checkStrftime("%s", &tm5, "67768036160140800"); + } + } + + return t_status; +} -- 2.15.1 --------------469AB21D4E43AC7FE61AB690--