+2019-11-15 Christian Biesinger <cbiesinger@google.com>
+
+ * maint.c (scoped_command_stats::print_time): Use localtime_r
+ instead of localtime (provided through gnulib if necessary).
+ * nat/linux-osdata.c (time_from_time_t): Use ctime_r instead
+ of ctime.
+
2019-11-15 Christian Biesinger <cbiesinger@google.com>
* gdbsupport/common-defs.h: Include time.h before pathmax.h to
auto millis = ticks % 1000;
std::time_t as_time = system_clock::to_time_t (now);
- struct tm *tm = localtime (&as_time);
+ struct tm tm;
+ localtime_r (&as_time, &tm);
char out[100];
- strftime (out, sizeof (out), "%F %H:%M:%S", tm);
+ strftime (out, sizeof (out), "%F %H:%M:%S", &tm);
printf_unfiltered ("%s.%03d - %s\n", out, (int) millis, msg);
}
{
time_t t = (time_t) seconds;
- strncpy (time, ctime (&t), maxlen);
+ /* Per the ctime_r manpage, this buffer needs to be at least 26
+ characters long. */
+ char buf[30];
+ const char *time_str = ctime_r (&t, buf);
+ strncpy (time, time_str, maxlen);
time[maxlen - 1] = '\0';
}
}