Code

screen_artist: check cursor position in cmd() method
authorMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 16:21:15 +0000 (18:21 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 16:21:15 +0000 (18:21 +0200)
Fix segmentation faults when the list is empty.

src/screen_artist.c

index 5c0ff30994d3a025ca330b70658a0bb7e3ebcf89..95e4d2236683e4dfcb60cda029e5b3433a643fba 100644 (file)
@@ -470,6 +470,9 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
        case CMD_PLAY:
                switch (mode) {
                case LIST_ARTISTS:
+                       if (browser.lw->selected >= artist_list->len)
+                               return true;
+
                        selected = g_ptr_array_index(artist_list,
                                                     browser.lw->selected);
                        open_album_list(c, g_strdup(selected));
@@ -603,6 +606,9 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
        case CMD_ADD:
                switch(mode) {
                case LIST_ARTISTS:
+                       if (browser.lw->selected >= artist_list->len)
+                               return true;
+
                        for (unsigned i = browser.lw->selected_start;
                             i <= browser.lw->selected_end; ++i) {
                                selected = g_ptr_array_index(artist_list, i);