From: Max Kellermann Date: Sun, 21 Sep 2008 20:45:04 +0000 (+0200) Subject: browser: check if the selection is valid X-Git-Tag: v0.12_alpha1~198 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ba91edfee95a6198e2db9804fee9ddfeffa8a199;p=ncmpc.git browser: check if the selection is valid Don't call filelist_get() with an invalid index. --- diff --git a/src/screen_browser.c b/src/screen_browser.c index d2c8aa0..4c8bc2e 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -250,7 +250,8 @@ enqueue_and_play(mpdclient_t *c, filelist_entry_t *entry) static struct filelist_entry * browser_get_selected(const struct screen_browser *browser) { - if (browser->filelist == NULL) + if (browser->filelist == NULL || + browser->lw->selected >= filelist_length(browser->filelist)) return NULL; return filelist_get(browser->filelist, browser->lw->selected); diff --git a/src/screen_file.c b/src/screen_file.c index 9dd5900..26b2739 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -62,6 +62,9 @@ handle_save(screen_t *screen, mpdclient_t *c) filelist_entry_t *entry; char *defaultname = NULL; + if (browser.lw->selected >= filelist_length(browser.filelist)) + return -1; + entry = filelist_get(browser.filelist, browser.lw->selected); if( entry && entry->entity ) { mpd_InfoEntity *entity = entry->entity; @@ -83,6 +86,9 @@ handle_delete(screen_t *screen, mpdclient_t *c) char *str, *buf; int key; + if (browser.lw->selected >= filelist_length(browser.filelist)) + return -1; + entry = filelist_get(browser.filelist, browser.lw->selected); if( entry==NULL || entry->entity==NULL ) return -1;