Codechange: use thread safe time functions

Functions like localtime, gmtime and asctime are not thread safe as they (might) reuse the same buffer. So use the safer _s/_r variant for localtime and gmtime, and use strftime in favour of asctime.
This commit is contained in:
rubidium42
2021-05-13 10:00:41 +02:00
committed by rubidium42
parent 297d6e20bf
commit aa5a8fe28a
7 changed files with 94 additions and 16 deletions

View File

@@ -32,8 +32,7 @@
#include "game/game_info.hpp"
#include "company_base.h"
#include "company_func.h"
#include <time.h>
#include "walltime_func.h"
#ifdef WITH_ALLEGRO
# include <allegro.h>
@@ -333,9 +332,8 @@ char *CrashLog::LogRecentNews(char *buffer, const char *last) const
*/
char *CrashLog::FillCrashLog(char *buffer, const char *last) const
{
time_t cur_time = time(nullptr);
buffer += seprintf(buffer, last, "*** OpenTTD Crash Report ***\n\n");
buffer += seprintf(buffer, last, "Crash at: %s", asctime(gmtime(&cur_time)));
buffer += UTCTime::Format(buffer, last, "Crash at: %Y-%m-%d %H:%M:%S (UTC)\n");
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);