From ce7f7611615bbe32c859a94a13f343097a120f19 Mon Sep 17 00:00:00 2001 From: waker Date: Wed, 25 Apr 2012 17:23:03 +0200 Subject: fixed plt_search_process bug which was creating single-linked list instead of double-linked; fixed plt_load bug which was leading to crash if playlist file fails to load early, e.g. if a file has size of 0 --- playlist.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'playlist.c') diff --git a/playlist.c b/playlist.c index 2c07fccf..cc8eca64 100644 --- a/playlist.c +++ b/playlist.c @@ -2134,12 +2134,14 @@ plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, in return NULL; } + playItem_t *last_added = NULL; uint8_t majorver; uint8_t minorver; playItem_t *it = NULL; char magic[4]; if (fread (magic, 1, 4, fp) != 4) { + trace ("failed to read magic\n"); goto load_fail; } if (strncmp (magic, "DBPL", 4)) { @@ -2166,8 +2168,6 @@ plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, in goto load_fail; } - playItem_t *last_added = NULL; - for (uint32_t i = 0; i < cnt; i++) { it = pl_item_alloc (); if (!it) { @@ -2379,6 +2379,7 @@ plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, in trace ("plt_load: success\n"); return last_added; load_fail: + plt_clear (plt); fprintf (stderr, "playlist load fail (%s)!\n", fname); if (fp) { fclose (fp); @@ -3551,6 +3552,7 @@ plt_search_process (playlist_t *playlist, const char *text) { if (abs (cmp) == cmpidx) { if (cmp > 0) { it->next[PL_SEARCH] = NULL; + it->prev[PL_SEARCH] = playlist->tail[PL_SEARCH]; if (playlist->tail[PL_SEARCH]) { playlist->tail[PL_SEARCH]->next[PL_SEARCH] = it; playlist->tail[PL_SEARCH] = it; @@ -3567,6 +3569,7 @@ plt_search_process (playlist_t *playlist, const char *text) { //fprintf (stderr, "%s -> %s match (%s.%s)\n", text, m->value, pl_find_meta_raw (it, ":URI"), m->key); // add to list it->next[PL_SEARCH] = NULL; + it->prev[PL_SEARCH] = playlist->tail[PL_SEARCH]; if (playlist->tail[PL_SEARCH]) { playlist->tail[PL_SEARCH]->next[PL_SEARCH] = it; playlist->tail[PL_SEARCH] = it; -- cgit v1.2.3