>From 4c9a3c65e279977af4e345748ba73ab0441dc04a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 11 Nov 2020 19:08:27 -0800 Subject: [PATCH 1/3] parse-datetime-tests: port to Alpine Linux 3.12.1 * tests/test-parse-datetime.c: Include errno.h for errno, and unistd.h for _SC_TZNAME_MAX and sysconf. (main): In the outlandishly-long time zone abbreviation test, do not exceed TZNAME_MAX as this has undefined behavior, and on Alpine Linux 3.12.1 it makes the test fail. --- ChangeLog | 9 +++++++++ tests/test-parse-datetime.c | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index a5999557b..e1828df64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-11-11 Paul Eggert + + parse-datetime-tests: port to Alpine Linux 3.12.1 + * tests/test-parse-datetime.c: Include errno.h for errno, + and unistd.h for _SC_TZNAME_MAX and sysconf. + (main): In the outlandishly-long time zone abbreviation test, + do not exceed TZNAME_MAX as this has undefined behavior, + and on Alpine Linux 3.12.1 it makes the test fail. + 2020-11-09 Pádraig Brady mgetgroups: avoid warning with clang diff --git a/tests/test-parse-datetime.c b/tests/test-parse-datetime.c index 920c9ae84..187e7c703 100644 --- a/tests/test-parse-datetime.c +++ b/tests/test-parse-datetime.c @@ -20,9 +20,11 @@ #include "parse-datetime.h" +#include #include #include #include +#include #include "macros.h" @@ -435,13 +437,21 @@ main (int argc _GL_UNUSED, char **argv) /* Outlandishly-long time zone abbreviations should not cause problems. */ { static char const bufprefix[] = "TZ=\""; - enum { tzname_len = 2000 }; + long int tzname_max = -1; + errno = 0; +#ifdef _SC_TZNAME_MAX + tzname_max = sysconf (_SC_TZNAME_MAX); +#endif + enum { tzname_alloc = 2000 }; + if (tzname_max < 0) + tzname_max = errno ? 6 : tzname_alloc; + int tzname_len = tzname_alloc < tzname_max ? tzname_alloc : tzname_max; static char const bufsuffix[] = "0\" 1970-01-01 01:02:03.123456789"; - enum { bufsize = sizeof bufprefix - 1 + tzname_len + sizeof bufsuffix }; + enum { bufsize = sizeof bufprefix - 1 + tzname_alloc + sizeof bufsuffix }; char buf[bufsize]; memcpy (buf, bufprefix, sizeof bufprefix - 1); memset (buf + sizeof bufprefix - 1, 'X', tzname_len); - strcpy (buf + bufsize - sizeof bufsuffix, bufsuffix); + strcpy (buf + sizeof bufprefix - 1 + tzname_len, bufsuffix); ASSERT (parse_datetime (&result, buf, &now)); LOG (buf, now, result); ASSERT (result.tv_sec == 1 * 60 * 60 + 2 * 60 + 3 -- 2.25.1