Skip to content

Commit

Permalink
Make err_helper time printing more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Jan 18, 2025
1 parent 3506092 commit 214e26e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/details/err_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ void err_helper::handle_ex(const std::string &origin, const source_loc &loc, con
}
last_report_time_ = now;
const auto tm_time = os::localtime();
char date_buf[32];
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
char date_buf[64];
if (std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time) == 0) {
std::snprintf(date_buf, sizeof(date_buf), "unknown time");
}
std::string msg;
if (loc.empty()) {
msg = fmt_lib::format("[*** LOG ERROR ***] [{}] [{}] {}\n", date_buf, origin, ex.what());
Expand Down

0 comments on commit 214e26e

Please sign in to comment.