From a2deff36893a3def2c95f520689803f0cc912d29 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 19 Feb 2024 20:58:09 -0800 Subject: [PATCH] fix(clock): crash on scrolling with local timezone (`""`) in the list While we at it, eliminate use of non-portable GCC conditional expression syntax. There are no significant side-effects that would justify use of the language extension. --- src/modules/clock.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index c889a13f..97e8a4a7 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -130,7 +130,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } auto waybar::modules::Clock::update() -> void { - auto tz{tzList_[tzCurrIdx_] ?: current_zone()}; + const auto* tz = tzList_[tzCurrIdx_] != nullptr ? tzList_[tzCurrIdx_] : current_zone(); const zoned_time now{tz, floor(system_clock::now())}; label_.set_markup(fmt_lib::vformat(locale_, format_, fmt_lib::make_format_args(now))); @@ -167,7 +167,8 @@ auto waybar::modules::Clock::getTZtext(sys_seconds now) -> std::string { std::stringstream os; for (size_t tz_idx{0}; tz_idx < tzList_.size(); ++tz_idx) { if (static_cast(tz_idx) == tzCurrIdx_) continue; - auto zt{zoned_time{tzList_[tz_idx], now}}; + const auto* tz = tzList_[tz_idx] != nullptr ? tzList_[tz_idx] : current_zone(); + auto zt{zoned_time{tz, now}}; os << fmt_lib::vformat(locale_, format_, fmt_lib::make_format_args(zt)) << '\n'; }