From 04205039f24ea6e71d2ce94c7cb7e1395f95179e Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 31 Jul 2023 17:28:00 +0200 Subject: fix Playlist.OrderedList() breaking the index of all songs Since 26f0033ebb5f8e7c204a042709e3dfa885eac868 and using Song pointers the copied Playlist in OrderedList actually holds the same Songs as the originally one. This and the side effects in Playlist.Pop (setting the index to -1) breaks the heap because all songs in the original queue now have a invalid index (-1). This is fixed by removing the side effect in Playlist.Pop(). --- playlist.go | 1 - playlist_test.go | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/playlist.go b/playlist.go index bc410e3..049354e 100644 --- a/playlist.go +++ b/playlist.go @@ -31,7 +31,6 @@ func (pl *Playlist) Pop() any { n := len(old) s := old[n-1] old[n-1] = nil // avoid memory leak - s.index = -1 // for safety *pl = old[0 : n-1] return s } diff --git a/playlist_test.go b/playlist_test.go index bb236ee..4829779 100644 --- a/playlist_test.go +++ b/playlist_test.go @@ -148,3 +148,11 @@ func TestPlOrderedList(t *testing.T) { t.Fail() } } + +func TestRemoveAfterOrderedList(t *testing.T) { + var pl Playlist + s := NewDummySong("Foo", "Bar") + pl.Add(s) + pl.OrderedList() + pl.RemoveSong(s) +} -- cgit v1.2.3