aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-06-02 20:40:30 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-06-02 20:40:30 +0000
commit8fca32b12d00db3ebfbbceb8a51880e505b5a780 (patch)
treeb5e09c4fe6583e003d1669d3a0efccd2d9fdc688 /src
parentc9c6f1f07127b443d6ee9f35240cf8118537ff37 (diff)
downloadmpd-8fca32b12d00db3ebfbbceb8a51880e505b5a780.tar.gz
mpd-8fca32b12d00db3ebfbbceb8a51880e505b5a780.tar.xz
mpd-8fca32b12d00db3ebfbbceb8a51880e505b5a780.zip
fix a segfault when deleteing the last song in the playlist and sync'ing metadata from the player
git-svn-id: https://svn.musicpd.org/mpd/trunk@1306 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/playlist.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/playlist.c b/src/playlist.c
index 4c0737d1b..75b812338 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -71,21 +71,21 @@ typedef struct _Playlist {
unsigned long version;
} Playlist;
-Playlist playlist;
-int playlist_state = PLAYLIST_STATE_STOP;
-int playlist_max_length;
-int playlist_stopOnError;
-int playlist_errorCount = 0;
-int playlist_queueError;
-int playlist_noGoToNext = 0;
+static Playlist playlist;
+static int playlist_state = PLAYLIST_STATE_STOP;
+static int playlist_max_length;
+static int playlist_stopOnError;
+static int playlist_errorCount = 0;
+static int playlist_queueError;
+static int playlist_noGoToNext = 0;
-int playlist_saveAbsolutePaths;
+static int playlist_saveAbsolutePaths;
-char * playlist_stateFile = NULL;
+static char * playlist_stateFile = NULL;
-void swapOrder(int a, int b);
-int playPlaylistOrderNumber(FILE * fp, int orderNum);
-void randomizeOrder(int start, int end);
+static void swapOrder(int a, int b);
+static int playPlaylistOrderNumber(FILE * fp, int orderNum);
+static void randomizeOrder(int start, int end);
void incrPlaylistVersion() {
static unsigned long max = ((unsigned long)1<<BITS_FOR_VERSION)-1;
@@ -93,6 +93,16 @@ void incrPlaylistVersion() {
if(playlist.version>=max) playlist.version = 0;
}
+static void incrPlaylistCurrent() {
+ if(playlist.current < 0) return;
+
+ if(playlist.current >= playlist.length-1) {
+ if(playlist.repeat) playlist.current = 0;
+ else playlist.current = -1;
+ }
+ else playlist.current++;
+}
+
void initPlaylist() {
char * test;
@@ -628,12 +638,15 @@ int deleteFromPlaylist(FILE * fp, int song) {
playerStop(stderr);
playlist_noGoToNext = 1;
}
- else if(/*playlist_state!=PLAYLIST_STATE_STOP &&*/
- playlist.current>songOrder) {
+
+ if(playlist.current>=playlist.length) {
+ incrPlaylistCurrent();
+ }
+ else if(playlist.current>songOrder) {
playlist.current--;
}
- if(/*playlist_state!=PLAYLIST_STATE_STOP && */playlist.queued>songOrder) {
+ if(playlist.queued>songOrder) {
playlist.queued--;
}
@@ -745,7 +758,7 @@ void syncCurrentPlayerDecodeMetadata() {
if(!songPlayer) return;
- if(playlist_state!=PLAYLIST_STATE_PLAY);
+ if(playlist_state!=PLAYLIST_STATE_PLAY) return;
song = playlist.songs[playlist.order[playlist.current]];
@@ -775,7 +788,7 @@ int currentSongInPlaylist(FILE * fp) {
syncPlaylistWithQueue(0);
- if(playlist.current<playlist.length) {
+ if(playlist.current>= 0 && playlist.current<playlist.length) {
return playPlaylistOrderNumber(fp,playlist.current);
}
else return stopPlaylist(fp);;
@@ -783,16 +796,6 @@ int currentSongInPlaylist(FILE * fp) {
return 0;
}
-void incrPlaylistCurrent() {
- if(playlist.current >= playlist.length || (!playlist.repeat &&
- playlist.current == playlist.length-1))
- {
- playlist.current = -1;
- }
- else if(playlist.current == playlist.length-1) playlist.current = 0;
- else if(playlist.current >= 0) playlist.current++;
-}
-
int nextSongInPlaylist(FILE * fp) {
if(playlist_state!=PLAYLIST_STATE_PLAY) return 0;