deck: Fix a segfault when calling next()

This can only be hit when the tagdb has no tracks in it, since you can't
add a NULL pointer to the recent queue.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-06-01 09:38:12 -04:00
parent 6f3fcaae6e
commit b8ea2c989d
2 changed files with 8 additions and 6 deletions

View File

@ -204,8 +204,8 @@ Track *deck :: next()
if (!track)
track = library :: get_queue()->next();
recent_queue.add(track);
if (track)
recent_queue.add(track);
return track;
}

View File

@ -15,7 +15,13 @@ static void test_init()
File f("deck", 0);
std::list<TempQueue>::iterator it;
test_equal(deck :: next(), TRACK_NULL);
test :: cp_data_dir();
tagdb :: init();
library :: init();
deck :: init();
test_equal(library :: get_queue()->has_flag(Q_RANDOM), true);
test_equal(deck :: get_queues().size(), (size_t)2);
@ -143,10 +149,6 @@ static void test_next_prev()
int main(int argc, char **argv)
{
test :: cp_data_dir();
tagdb :: init();
library :: init();
run_test("Deck Init Test", test_init);
run_test("Deck Create, Move and Destroy Test", test_create_mv_destroy);
run_test("Deck Next and Prev Test", test_next_prev);