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

@@ -219,18 +219,16 @@ std::string GetDebugString()
/**
* Get the prefix for logs; if show_date_in_logs is enabled it returns
* the date, otherwise it returns nothing.
* @return the prefix for logs (do not free), never nullptr
* the date, otherwise it returns an empty string.
* @return the prefix for logs.
*/
const char *GetLogPrefix()
std::string GetLogPrefix()
{
static std::string _log_prefix;
std::string log_prefix;
if (_settings_client.gui.show_date_in_logs) {
_log_prefix = fmt::format("[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(nullptr)));
} else {
_log_prefix.clear();
log_prefix = fmt::format("[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(nullptr)));
}
return _log_prefix.c_str();
return log_prefix;
}
/**