summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-10-16 19:56:47 +0000
committerrubidium <rubidium@openttd.org>2011-10-16 19:56:47 +0000
commit0656660f22eb334a53d6435f187eba2592622a27 (patch)
tree789a0417eb9c3193a414502487c0f0f0a015d58d
parentf04746a9ff50e7f9c3813ef0a8498172743f4c28 (diff)
downloadopenttd-0656660f22eb334a53d6435f187eba2592622a27.tar.xz
(svn r23034) -Fix: make sure the custom playlists are 0 terminated
-rw-r--r--src/music_gui.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/music_gui.cpp b/src/music_gui.cpp
index 94e3f191b..17f09f47c 100644
--- a/src/music_gui.cpp
+++ b/src/music_gui.cpp
@@ -79,20 +79,24 @@ static byte * const _playlists[] = {
/**
* Validate a playlist.
- * @param playlist the playlist to validate
+ * @param playlist The playlist to validate.
+ * @param last The last location in the list.
*/
-void ValidatePlaylist(byte *playlist)
+void ValidatePlaylist(byte *playlist, const byte *last)
{
- while (*playlist != 0) {
+ while (*playlist != 0 && playlist <= last) {
/* Song indices are saved off-by-one so 0 is "nothing". */
if (*playlist <= NUM_SONGS_AVAILABLE && !StrEmpty(GetSongName(*playlist - 1))) {
playlist++;
continue;
}
- for (byte *p = playlist; *p != 0; p++) {
+ for (byte *p = playlist; *p != 0 && p <= last; p++) {
p[0] = p[1];
}
}
+
+ /* Make sure the list is null terminated. */
+ *last = 0;
}
/** Initialize the playlists */
@@ -118,8 +122,8 @@ void InitializeMusic()
_playlists[k + 1][j] = 0;
}
- ValidatePlaylist(_settings_client.music.custom_1);
- ValidatePlaylist(_settings_client.music.custom_2);
+ ValidatePlaylist(_settings_client.music.custom_1, lastof(_settings_client.music.custom_1));
+ ValidatePlaylist(_settings_client.music.custom_2, lastof(_settings_client.music.custom_2));
if (BaseMusic::GetUsedSet()->num_available < _music_wnd_cursong) {
/* If there are less songs than the currently played song,