From bb40ef479faddf727bbc6a31d7c4806e58f0a625 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 12 Jun 2017 08:19:21 -0400 Subject: [PATCH] core/playlists/generic: Initialize pl_random and pl_length These fields were working fine for statically initialized playlists, but they get set to garbage values when g_malloc()-ing a playlist. Let's make sure they get initialized properly with the rest of the playlist. Fixes #107: Initialize all values in playlist_generic_init() Signed-off-by: Anna Schumaker --- core/playlists/generic.c | 4 +++- tests/core/playlists/user.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/playlists/generic.c b/core/playlists/generic.c index 39317f10..156a1ab2 100644 --- a/core/playlists/generic.c +++ b/core/playlists/generic.c @@ -42,8 +42,10 @@ void playlist_generic_init(struct playlist *playlist) { if (playlist) { g_queue_init(&playlist->pl_tracks); - playlist->pl_sort = NULL; + playlist->pl_length = 0; + playlist->pl_random = false; playlist->pl_current = NULL; + playlist->pl_sort = NULL; playlist->pl_search = NULL; } } diff --git a/tests/core/playlists/user.c b/tests/core/playlists/user.c index f8d5435b..ae197bca 100644 --- a/tests/core/playlists/user.c +++ b/tests/core/playlists/user.c @@ -18,6 +18,8 @@ void test_user() playlist = playlist_new(PL_USER, "Test Playlist"); g_assert_nonnull(playlist); g_assert_cmpuint(playlist->pl_id, ==, 0); + g_assert_cmpuint(playlist->pl_length, ==, 0); + g_assert_false(playlist->pl_random); g_assert_null(playlist_new(PL_USER, "Test Playlist")); g_assert_cmpuint(db->db_size, ==, 1);