From 73f4eb511cf80cf52b78627347727ca02774b731 Mon Sep 17 00:00:00 2001 From: John Moffett Date: Thu, 23 Mar 2023 13:52:22 -0400 Subject: Check that the Timestamp String is valid The current `FormatISO8601DateTime` function will return an empty string if it encounters an error when converting the `int64_t` seconds since epoch to a formatted date time. In the unlikely case that happens, `strStamped.pop_back()` would be undefined behavior. --- src/logging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/logging.cpp') diff --git a/src/logging.cpp b/src/logging.cpp index a9b2a2b33a..2d278bcef8 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -352,7 +352,7 @@ std::string BCLog::Logger::LogTimestampStr(const std::string& str) const auto now{SystemClock::now()}; const auto now_seconds{std::chrono::time_point_cast(now)}; strStamped = FormatISO8601DateTime(TicksSinceEpoch(now_seconds)); - if (m_log_time_micros) { + if (m_log_time_micros && !strStamped.empty()) { strStamped.pop_back(); strStamped += strprintf(".%06dZ", Ticks(now - now_seconds)); } -- cgit v1.2.3