diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-11-11 19:08:27 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-11-11 19:21:19 -0800 |
commit | 4c9a3c65e279977af4e345748ba73ab0441dc04a (patch) | |
tree | 98c7618deb47cd3a14cd695839ad35f07b3ceee5 /tests/test-parse-datetime.c | |
parent | 1833000138491bb45df7df0627a33774fd52682d (diff) | |
download | gnulib-4c9a3c65e279977af4e345748ba73ab0441dc04a.tar.gz |
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.
Diffstat (limited to 'tests/test-parse-datetime.c')
-rw-r--r-- | tests/test-parse-datetime.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tests/test-parse-datetime.c b/tests/test-parse-datetime.c index 920c9ae841..187e7c703b 100644 --- a/tests/test-parse-datetime.c +++ b/tests/test-parse-datetime.c @@ -20,9 +20,11 @@ #include "parse-datetime.h" +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #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 |