]> Savannah Git Hosting - gnulib.git/commitdiff
parse-datetime-tests: port to Alpine Linux 3.12.1
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 12 Nov 2020 03:08:27 +0000 (19:08 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 12 Nov 2020 03:21:19 +0000 (19:21 -0800)
* 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
tests/test-parse-datetime.c

index a5999557bce0aeda09a41653cd0ccca53c93f55c..e1828df64c4db3bc26ce23ad007baa0f6e25111c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-11-11  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <P@draigBrady.com>
 
        mgetgroups: avoid warning with clang
index 920c9ae8410d151fc0ef4e706f1bf64037c9da7d..187e7c703bdd321f7a7097107f2401e22aecd862 100644 (file)
 
 #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