From b8ea2c989d17d25480d0b295786ae91e46863d57 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 1 Jun 2014 09:38:12 -0400 Subject: [PATCH] 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 --- lib/deck.cpp | 4 ++-- tests/deck.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/deck.cpp b/lib/deck.cpp index db2c284f..1940643e 100644 --- a/lib/deck.cpp +++ b/lib/deck.cpp @@ -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; } diff --git a/tests/deck.cpp b/tests/deck.cpp index 21f82b14..7057ac7c 100644 --- a/tests/deck.cpp +++ b/tests/deck.cpp @@ -15,7 +15,13 @@ static void test_init() File f("deck", 0); std::list::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);