diff options
| author | Hardeep Sidhu <dyp@pobox.com> | 2006-04-18 16:44:51 +0000 |
|---|---|---|
| committer | Hardeep Sidhu <dyp@pobox.com> | 2006-04-18 16:44:51 +0000 |
| commit | 095ad1a39c5bacfa2fba30cf1f9e5c82c31ae674 (patch) | |
| tree | fbe400c9299e811f173075cb7d3b0ed872115804 | |
| parent | d0de1aafac2e262810f4f6f01af40d114263c5bb (diff) | |
| download | rockbox-095ad1a39c5bacfa2fba30cf1f9e5c82c31ae674.zip rockbox-095ad1a39c5bacfa2fba30cf1f9e5c82c31ae674.tar.gz rockbox-095ad1a39c5bacfa2fba30cf1f9e5c82c31ae674.tar.bz2 rockbox-095ad1a39c5bacfa2fba30cf1f9e5c82c31ae674.tar.xz | |
Minor fix for insert_shuffle when playlist is empty
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9716 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/playlist.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index e96e7d3..f3339a6 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -602,20 +602,25 @@ static int add_track_to_playlist(struct playlist_info* playlist, break; case PLAYLIST_INSERT_SHUFFLED: { - int offset; - int n = playlist->amount - - rotate_index(playlist, playlist->index); - - if (n > 0) - offset = rand() % n; + if (playlist->amount > 0) + { + int offset; + int n = playlist->amount - + rotate_index(playlist, playlist->index); + + if (n > 0) + offset = rand() % n; + else + offset = 0; + + position = playlist->index + offset + 1; + if (position >= playlist->amount) + position -= playlist->amount; + + insert_position = position; + } else - offset = 0; - - position = playlist->index + offset + 1; - if (position >= playlist->amount) - position -= playlist->amount; - - insert_position = position; + position = insert_position = 0; break; } } |