playlist: safely search the playlist for deleted song

When a song file is deleted during database update, all pointers to it
must be removed from the playlist.  The "for" loop in
deleteASongFromPlaylist() did not deal with multiple copies of the
deleted song properly, and left instances of the (to-be-invalidated)
pointer in.  Fix this by reversing the loop.
This commit is contained in:
Max Kellermann 2009-01-14 11:41:22 +01:00
parent 2af1742fcf
commit 2c540ee8a4
2 changed files with 8 additions and 1 deletions

7
NEWS
View File

@ -15,6 +15,13 @@ ver 0.15 - (200?/??/??)
* fix cross-fading bug: it used to play some chunks of the new song twice * fix cross-fading bug: it used to play some chunks of the new song twice
* --create-db starts the MPD daemon instead of exiting * --create-db starts the MPD daemon instead of exiting
* input_curl: honour http_proxy_* config directives * input_curl: honour http_proxy_* config directives
* playlist
- fix assertion failure during playlist load
- implement Fisher-Yates shuffle properly
- safely search the playlist for deleted song
* use custom PRNG for volume dithering (speedup)
* detect libid3tag without pkg-config
ver 0.14 (2008/12/25) ver 0.14 (2008/12/25)
* audio outputs: * audio outputs:

View File

@ -764,7 +764,7 @@ deleteASongFromPlaylist(const struct song *song)
if (NULL == playlist.songs) if (NULL == playlist.songs)
return; return;
for (unsigned i = 0; i < playlist.length; i++) for (int i = playlist.length - 1; i >= 0; --i)
if (song == playlist.songs[i]) if (song == playlist.songs[i])
deleteFromPlaylist(i); deleteFromPlaylist(i);