mpd: fix floating point exception when adding random tags/songs

This commit is contained in:
Benoît Dardenne
2015-01-14 22:55:03 +01:00
committed by Andrzej Rybczak
parent 9888c3106e
commit af17e7eadf
2 changed files with 6 additions and 2 deletions

View File

@@ -505,7 +505,7 @@ bool Connection::AddRandomTag(mpd_tag_type tag, size_t number)
else
{
std::random_shuffle(tags.begin(), tags.end());
auto it = tags.begin()+rand()%(tags.size()-number);
auto it = tags.begin();
for (size_t i = 0; i < number && it != tags.end(); ++i)
{
StartSearch(1);
@@ -546,7 +546,7 @@ bool Connection::AddRandomSongs(size_t number)
{
std::random_shuffle(files.begin(), files.end());
StartCommandsList();
auto it = files.begin()+rand()%(std::max(size_t(1), files.size()-number));
auto it = files.begin();
for (size_t i = 0; i < number && it != files.end(); ++i, ++it)
AddSong(*it);
CommitCommandsList();