From 9d8a8356b56df21a4b941a57ebe99f6915f3456b Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Jul 2026 22:02:17 +0200 Subject: [PATCH] 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 --- src/modules/mpd/mpd.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/mpd/mpd.cpp b/src/modules/mpd/mpd.cpp index 8598628d..035183a0 100644 --- a/src/modules/mpd/mpd.cpp +++ b/src/modules/mpd/mpd.cpp @@ -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) {