summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-09-10 16:33:42 +0000
committerrubidium <rubidium@openttd.org>2014-09-10 16:33:42 +0000
commit4438821b806460291630bf05c755699dfc8ca321 (patch)
treec4f16cc7ccd058fd02a688cb58371e71504ae2a8 /src
parented9cadade430b9b38079c3139a579bd9a29a54e9 (diff)
downloadopenttd-4438821b806460291630bf05c755699dfc8ca321.tar.xz
(svn r26809) -Fix: do not dereference the -1 index of the file names array of music files. It definitely breaks on m68k, and might cause failures on other platforms as well
Diffstat (limited to 'src')
-rw-r--r--src/music_gui.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/music_gui.cpp b/src/music_gui.cpp
index 1a6a4ca20..e9ca7acf6 100644
--- a/src/music_gui.cpp
+++ b/src/music_gui.cpp
@@ -202,12 +202,17 @@ static void SelectSongToPlay()
memset(_cur_playlist, 0, sizeof(_cur_playlist));
do {
- const char *filename = BaseMusic::GetUsedSet()->files[_playlists[_settings_client.music.playlist][i] - 1].filename;
- /* We are now checking for the existence of that file prior
- * to add it to the list of available songs */
- if (!StrEmpty(filename) && FioCheckFileExists(filename, BASESET_DIR)) {
- _cur_playlist[j] = _playlists[_settings_client.music.playlist][i];
- j++;
+ /* File is the index into the file table of the music set. The play list uses 0 as 'no entry',
+ * so we need to subtract 1. In case of 'no entry' (file = -1), just skip adding it outright. */
+ int file = _playlists[_settings_client.music.playlist][i] - 1;
+ if (file >= 0) {
+ const char *filename = BaseMusic::GetUsedSet()->files[file].filename;
+ /* We are now checking for the existence of that file prior
+ * to add it to the list of available songs */
+ if (!StrEmpty(filename) && FioCheckFileExists(filename, BASESET_DIR)) {
+ _cur_playlist[j] = _playlists[_settings_client.music.playlist][i];
+ j++;
+ }
}
} while (_playlists[_settings_client.music.playlist][++i] != 0 && j < lengthof(_cur_playlist) - 1);