Skip to content

Commit 73f4eb5

Browse files
committed
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.
1 parent 381593c commit 73f4eb5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ std::string BCLog::Logger::LogTimestampStr(const std::string& str)
352352
const auto now{SystemClock::now()};
353353
const auto now_seconds{std::chrono::time_point_cast<std::chrono::seconds>(now)};
354354
strStamped = FormatISO8601DateTime(TicksSinceEpoch<std::chrono::seconds>(now_seconds));
355-
if (m_log_time_micros) {
355+
if (m_log_time_micros && !strStamped.empty()) {
356356
strStamped.pop_back();
357357
strStamped += strprintf(".%06dZ", Ticks<std::chrono::microseconds>(now - now_seconds));
358358
}

0 commit comments

Comments
 (0)