Code

browse: ensure that filelist!=NULL
authorMax Kellermann <max@duempel.org>
Sun, 21 Sep 2008 20:45:08 +0000 (22:45 +0200)
committerMax Kellermann <max@duempel.org>
Sun, 21 Sep 2008 20:45:08 +0000 (22:45 +0200)
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
src/screen_search.c

index 2f97c723a7d7b70293f4c670f82911f4f4f0569c..cf2d310ce920659afb83eef17a18f8f888808054 100644 (file)
@@ -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);
 
index 803772f4fd46535d57add4a439ffdb80fb76deb3..7dfc58d0f05dc85ceb59b5f700fc449309a2da6a 100644 (file)
@@ -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));