diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-07-31 17:28:00 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-07-31 17:28:00 +0200 |
| commit | 04205039f24ea6e71d2ce94c7cb7e1395f95179e (patch) | |
| tree | 9e16ceaa1cce5db8c41fcdc0120f276baa196193 | |
| parent | 78dc143e4585a3ab5a4d173f50571b4842a4e347 (diff) | |
| download | WRMS-04205039f24ea6e71d2ce94c7cb7e1395f95179e.tar.gz WRMS-04205039f24ea6e71d2ce94c7cb7e1395f95179e.zip | |
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().
| -rw-r--r-- | playlist.go | 1 | ||||
| -rw-r--r-- | playlist_test.go | 8 |
2 files changed, 8 insertions, 1 deletions
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) +} |
