libsaria: Don't use random if playlist size == 1

This could cause a floating point exception when I mod-by-zero...

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-11-11 14:03:14 -05:00
parent 1205a94aa7
commit 83f8b1e543
1 changed files with 7 additions and 5 deletions

View File

@ -99,17 +99,19 @@ namespace libsaria
Track *Playlist::next()
{
Track *track;
unsigned int size = get_size();
if (get_size() == 0)
if (size == 0)
return NULL;
if (check_flag(PL_RANDOM))
else if (size == 1)
cur = 0;
else if (check_flag(PL_RANDOM))
cur += rand() % ((get_size() * 3) / 4);
else if (flags & PL_NO_DRAIN)
cur++;
if (cur >= plist.size())
cur -= plist.size();
if (cur >= size)
cur -= size;
track = plist[cur];
if (!(flags & PL_NO_DRAIN))