From 063648606de65ce668c3357ec7b08792ae055219 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 21 Sep 2008 22:45:08 +0200 Subject: [PATCH] browse: ensure that filelist!=NULL There are several places where browser.filelist can become NULL. Catch that everywhere and generate an empty filelist in this case. --- src/screen_artist.c | 3 +++ src/screen_search.c | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/screen_artist.c b/src/screen_artist.c index 2f97c72..cf2d310 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -121,6 +121,9 @@ update_metalist(mpdclient_t *c, char *m_artist, char *m_album) mpdclient_filelist_search_utf8(c, TRUE, MPD_TABLE_ALBUM, album); + if (browser.filelist == NULL) + browser.filelist = filelist_new(NULL); + /* add a dummy entry for ".." */ filelist_prepend(browser.filelist, NULL); diff --git a/src/screen_search.c b/src/screen_search.c index 803772f..7dfc58d 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -168,7 +168,7 @@ search_clear(mpd_unused screen_t *screen, mpdclient_t *c, if (browser.filelist) { mpdclient_remove_playlist_callback(c, playlist_changed_callback); filelist_free(browser.filelist); - browser.filelist = NULL; + browser.filelist = filelist_new(NULL); } if (clear_pattern && pattern) { g_free(pattern); @@ -186,15 +186,23 @@ filelist_search(mpdclient_t *c, mpd_unused int exact_match, int table, if (table == SEARCH_ARTIST_TITLE) { list = mpdclient_filelist_search(c, FALSE, MPD_TABLE_ARTIST, local_pattern); + if (list == NULL) + list = filelist_new(NULL); + list2 = mpdclient_filelist_search(c, FALSE, MPD_TABLE_TITLE, local_pattern); + if (list2 != NULL) { + filelist_move(list, list2); + filelist_free(list2); + } - filelist_move(list, list2); - filelist_free(list2); filelist_sort(list, compare_filelistentry_format); list->updated = TRUE; - } else + } else { list = mpdclient_filelist_search(c, FALSE, table, local_pattern); + if (list == NULL) + list = filelist_new(NULL); + } return list; } @@ -331,6 +339,9 @@ search_new(screen_t *screen, mpdclient_t *c) mode[options.search_mode].table, pattern); + if (browser.filelist == NULL) + browser.filelist = filelist_new(NULL); + sync_highlights(c, browser.filelist); mpdclient_install_playlist_callback(c, playlist_changed_callback); list_window_check_selected(browser.lw, filelist_length(browser.filelist)); -- 2.30.2