From 5b121352c2b23857d845c0174607cbbf1ae38bce Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 7 Mar 2022 22:23:36 +0200 Subject: [PATCH] utils: Handle failing g_date_time_new_... Possibly, this caused a crashed under some scenarios (though couldn't reproduce). --- lib/utils/mu-utils.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/utils/mu-utils.cc b/lib/utils/mu-utils.cc index 5afd7ab4..ee33518b 100644 --- a/lib/utils/mu-utils.cc +++ b/lib/utils/mu-utils.cc @@ -266,12 +266,18 @@ Mu::date_to_time_t_string(int64_t t) std::string Mu::time_to_string(const std::string& frm, time_t t, bool utc) { - GDateTime* dt = [&] { + GDateTime* dt = std::invoke([&] { if (utc) return g_date_time_new_from_unix_utc(t); else return g_date_time_new_from_unix_local(t); - }(); + }); + + if (!dt) { + g_warning("time_t out of range: <%" G_GUINT64_FORMAT ">", + static_cast(t)); + return {}; + } char* str = g_date_time_format(dt, frm.c_str()); g_date_time_unref(dt);