Use gmtime_r() and localtime_r() instead of gmtime() and localtime().

This commit is contained in:
Todd C. Miller
2021-09-17 10:55:06 -06:00
parent fa71679b5a
commit 18f1884ddc
15 changed files with 135 additions and 166 deletions

View File

@@ -37,13 +37,13 @@ char *
get_timestr(time_t tstamp, int log_year)
{
static char buf[128];
struct tm *timeptr;
struct tm tm;
if ((timeptr = localtime(&tstamp)) != NULL) {
if (localtime_r(&tstamp, &tm) != NULL) {
/* strftime() does not guarantee to NUL-terminate so we must check. */
buf[sizeof(buf) - 1] = '\0';
if (strftime(buf, sizeof(buf), log_year ? "%h %e %T %Y" : "%h %e %T",
timeptr) != 0 && buf[sizeof(buf) - 1] == '\0')
&tm) != 0 && buf[sizeof(buf) - 1] == '\0')
return buf;
}
return NULL;