From fb1545bccdd22866504923fd856a203dd312c1ee Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 23 Nov 2024 23:46:40 +0100 Subject: Check the retval of localtime() --- FICS/gamedb.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 6fa0ae2..dea8a67 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -553,6 +553,7 @@ movesToString(int g, int pgn) char tmp[160] = { '\0' }; int i, col; int wr, br; + struct tm *tm_ptr = NULL; time_t curTime; wr = garray[g].white_rating; @@ -569,11 +570,15 @@ movesToString(int g, int pgn) bstr[garray[g].type], serv_name, serv_loc); - strftime(tmp, sizeof(tmp), - "[Date \"%Y.%m.%d\"]\n" - "[Time \"%H:%M:%S\"]\n", - localtime(&curTime)); // XXX - mstrlcat(gameString, tmp, sizeof gameString); + + if ((tm_ptr = localtime(&curTime)) != NULL) { + strftime(tmp, sizeof(tmp), + "[Date \"%Y.%m.%d\"]\n" + "[Time \"%H:%M:%S\"]\n", + tm_ptr); + mstrlcat(gameString, tmp, sizeof gameString); + } else + warn("%s: localtime", __func__); msnprintf(tmp, sizeof tmp, "[Round \"-\"]\n" -- cgit v1.2.3