Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
Fix toggle_playing_status bounds check and error propagation - Guard highlight_index against out-of-bounds queue access - Return 1 on failure with MPD error message logged - Only fetch status and expose on success - Use pointer instead of struct copy
src/ui.c | 18 +++++++++++-------
diff --git a/src/ui.c b/src/ui.c index db56be26e0cbb14ad05cfc9ec247a7442a8d056b..00f42e33bd84aeddf89d0ed8a616e237c3c3b241 100644 --- a/src/ui.c +++ b/src/ui.c @@ -134,14 +134,18 @@ static int toggle_playing_status(struct seamus_frontend *seamus) { - log_info("Current position %d", seamus->highlight_index); - struct seamus_song song = seamus->queue[seamus->highlight_index]; - log_info("Current song on queue %d - %s", song.song_id, song.title); + if (seamus->highlight_index < 0 || seamus->highlight_index >= seamus->queue_size) { + log_info("No song at index %d to play", seamus->highlight_index); + return 1; + } - if (mpd_run_play_id(seamus->conn, song.song_id)) { - log_info("Requested to play song"); - } else { - log_info("Failed to play song"); + struct seamus_song *song = &seamus->queue[seamus->highlight_index]; + log_info("Current position %d - %s", seamus->highlight_index, song->title); + + if (!mpd_run_play_id(seamus->conn, song->song_id)) { + const char *msg = mpd_connection_get_error_message(seamus->conn); + log_error("Failed to play song: %s", msg); + return 1; } fetch_current_status(seamus);