pivot-table: Avoid ctime_r() for portability reasons.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 1 Jan 2020 17:19:14 +0000 (17:19 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 1 Jan 2020 17:19:14 +0000 (17:19 +0000)
ctime_r() isn't in mingw or Gnulib and it's best to avoid it in any
case because POSIX says it is obsolescent and it has buffer overflow
issues.

Reported by Harry Thijssen.

src/output/pivot-table.c

index 031656227bfe6b05dfa58b3444f73fa6ae7d893d..924a14cc9b1490eff01f5f50b82ae5c55e31445d 100644 (file)
@@ -1487,8 +1487,11 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
   if (table->date)
     {
       indent (indentation);
-      char buf[26];
-      printf ("date: %s", ctime_r (&table->date, buf));
+
+      struct tm *tm = localtime (&table->date);
+      printf ("date: %d-%02d-%02d %d:%02d:%02d\n", tm->tm_year + 1900,
+              tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min,
+              tm->tm_sec);
     }
 
   indent (indentation);