1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-23 13:12:40 +01:00

Fix #11646: Non-thread safe shared buffer returned from GetLogPrefix().

Return string from GetLogPrefix instead of shared string's buffer.
This commit is contained in:
Peter Nelson
2023-12-30 00:07:51 +00:00
committed by rubidium42
parent 2b599c9d00
commit 28ef5146ba
3 changed files with 10 additions and 13 deletions

View File

@@ -51,10 +51,9 @@ static void IConsoleWriteToLogFile(const std::string &string)
{
if (_iconsole_output_file != nullptr) {
/* if there is an console output file ... also print it there */
const char *header = GetLogPrefix();
if ((strlen(header) != 0 && fwrite(header, strlen(header), 1, _iconsole_output_file) != 1) ||
fwrite(string.c_str(), string.size(), 1, _iconsole_output_file) != 1 ||
fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
try {
fmt::print(_iconsole_output_file, "{}{}\n", GetLogPrefix(), string);
} catch (const std::system_error &) {
fclose(_iconsole_output_file);
_iconsole_output_file = nullptr;
IConsolePrint(CC_ERROR, "Cannot write to console log file; closing the log file.");