lib/, src/: Call gmtime_r(3) instead of gmtime(3)

It's trivial to do the change, and it removes a CodeQL warning.
We don't need to be reentrant, but it doesn't hurt either.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-01-29 15:53:34 +01:00
committed by Serge Hallyn
parent 8fcf6cccff
commit bed18501b1
2 changed files with 10 additions and 11 deletions
+4 -5
View File
@@ -25,8 +25,8 @@ inline void day_to_str(size_t size, char buf[size], long day);
inline void
day_to_str(size_t size, char buf[size], long day)
{
time_t date;
const struct tm *tm;
time_t date;
struct tm tm;
if (day < 0) {
strtcpy(buf, "never", size);
@@ -38,13 +38,12 @@ day_to_str(size_t size, char buf[size], long day)
return;
}
tm = gmtime(&date);
if (tm == NULL) {
if (gmtime_r(&date, &tm) == NULL) {
strtcpy(buf, "future", size);
return;
}
if (strftime(buf, size, "%Y-%m-%d", tm) == 0)
if (strftime(buf, size, "%Y-%m-%d", &tm) == 0)
strtcpy(buf, "future", size);
}
+6 -6
View File
@@ -237,7 +237,7 @@ print_day_as_date(long day)
{
char buf[80];
time_t date;
struct tm *tp;
struct tm tm;
if (day < 0) {
puts(_("never"));
@@ -248,13 +248,13 @@ print_day_as_date(long day)
return;
}
tp = gmtime (&date);
if (NULL == tp) {
if (gmtime_r(&date, &tm) == NULL) {
(void) printf ("time_t: %lu\n", (unsigned long)date);
} else {
(void) strftime (buf, sizeof buf, iflg ? "%Y-%m-%d" : "%b %d, %Y", tp);
(void) puts (buf);
return;
}
(void) strftime (buf, sizeof buf, iflg ? "%Y-%m-%d" : "%b %d, %Y", &tm);
(void) puts (buf);
}