mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Make conversions between std::chrono time_point and string safer by not using "localtime" directly.
This commit is contained in:
parent
6d3de520e8
commit
5cf2a958eb
6 changed files with 54 additions and 30 deletions
|
@ -99,7 +99,13 @@ namespace Debug
|
|||
prefix[0] = '[';
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto time = std::chrono::system_clock::to_time_t(now);
|
||||
prefixSize = std::strftime(prefix + 1, sizeof(prefix) - 1, "%T", std::localtime(&time)) + 1;
|
||||
tm time_info{};
|
||||
#ifdef _WIN32
|
||||
(void)localtime_s(&time_info, &time);
|
||||
#else
|
||||
(void)localtime_r(&time, &time_info);
|
||||
#endif
|
||||
prefixSize = std::strftime(prefix + 1, sizeof(prefix) - 1, "%T", &time_info) + 1;
|
||||
char levelLetter = " EWIVD*"[int(level)];
|
||||
const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
|
||||
prefixSize += snprintf(prefix + prefixSize, sizeof(prefix) - prefixSize, ".%03u %c] ",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue