fix(mpd): don't dereference a null song when the queue is cleared

mpd_run_current_song() returns NULL when there is no current song (e.g.
after `mpc clear`), leaving song_ null. setLabel() always evaluates the
fmt::format() tag arguments -- even for format-stopped -- so getTag() and
getFilename() would call mpd_song_get_tag()/mpd_song_get_uri() on a null
song and segfault. Guard both against a null song_.

Fixes #5183
This commit is contained in:
Alex
2026-07-05 22:03:28 +02:00
parent 6888243c50
commit 9d8a8356b5
+5 -1
View File
@@ -62,7 +62,8 @@ auto waybar::modules::MPD::update() -> void {
std::string waybar::modules::MPD::getTag(mpd_tag_type type, unsigned idx) const {
std::string result =
config_["unknown-tag"].isString() ? config_["unknown-tag"].asString() : "N/A";
const char* tag = mpd_song_get_tag(song_.get(), type, idx);
// song_ is null when there is no current song (e.g. after `mpc clear`) (#5183).
const char* tag = song_ ? mpd_song_get_tag(song_.get(), type, idx) : nullptr;
// mpd_song_get_tag can return NULL, so make sure it's valid before setting
if (tag) result = tag;
@@ -71,6 +72,9 @@ std::string waybar::modules::MPD::getTag(mpd_tag_type type, unsigned idx) const
}
std::string waybar::modules::MPD::getFilename() const {
if (!song_) {
return "";
}
std::string path = mpd_song_get_uri(song_.get());
size_t position = path.find_last_of("/");
if (position == std::string::npos) {