mirror of
https://github.com/djcb/mu.git
synced 2024-06-26 07:29:17 +02:00
utils: Handle failing g_date_time_new_...
Possibly, this caused a crashed under some scenarios (though couldn't reproduce).
This commit is contained in:
parent
1fc0a6047f
commit
5b121352c2
|
@ -266,12 +266,18 @@ Mu::date_to_time_t_string(int64_t t)
|
||||||
std::string
|
std::string
|
||||||
Mu::time_to_string(const std::string& frm, time_t t, bool utc)
|
Mu::time_to_string(const std::string& frm, time_t t, bool utc)
|
||||||
{
|
{
|
||||||
GDateTime* dt = [&] {
|
GDateTime* dt = std::invoke([&] {
|
||||||
if (utc)
|
if (utc)
|
||||||
return g_date_time_new_from_unix_utc(t);
|
return g_date_time_new_from_unix_utc(t);
|
||||||
else
|
else
|
||||||
return g_date_time_new_from_unix_local(t);
|
return g_date_time_new_from_unix_local(t);
|
||||||
}();
|
});
|
||||||
|
|
||||||
|
if (!dt) {
|
||||||
|
g_warning("time_t out of range: <%" G_GUINT64_FORMAT ">",
|
||||||
|
static_cast<guint64>(t));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
char* str = g_date_time_format(dt, frm.c_str());
|
char* str = g_date_time_format(dt, frm.c_str());
|
||||||
g_date_time_unref(dt);
|
g_date_time_unref(dt);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user