From c45445f8aa4b06c6de0a5fb3254da99df73442ed Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 6 Dec 2006 23:14:49 +0000 Subject: [PATCH] Null pointer checks for music filenames git-svn-id: https://svn.eduke32.com/eduke32@389 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 15 ++++++++++----- polymer/eduke32/source/gameexec.c | 5 +++-- polymer/eduke32/source/menus.c | 5 ++++- polymer/eduke32/source/premap.c | 3 ++- polymer/eduke32/source/savegame.c | 3 ++- polymer/eduke32/source/sounds.c | 4 ++++ 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 5c534a9fe..dfb7c7129 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -7853,15 +7853,18 @@ void nonsharedkeys(void) { if (i == 5 && ps[myconnectindex].fta > 0 && ps[myconnectindex].ftq == 26) { - i = (VOLUMEALL?num_volumes*MAXLEVELS:6); + i = (VOLUMEALL?MAXVOLUMES*MAXLEVELS:6); music_select++; while ((music_fn[0][(unsigned char)music_select] == NULL) && music_select < i) music_select++; if (music_select == i) music_select = 0; - Bsprintf(fta_quotes[26],"PLAYING %s",&music_fn[0][(unsigned char)music_select][0]); - FTA(26,&ps[myconnectindex]); - playmusic(&music_fn[0][(unsigned char)music_select][0]); + if (music_fn[0][(unsigned char)music_select] != NULL) + { + Bsprintf(fta_quotes[26],"PLAYING %s",&music_fn[0][(unsigned char)music_select][0]); + FTA(26,&ps[myconnectindex]); + playmusic(&music_fn[0][(unsigned char)music_select][0]); + } return; } @@ -8077,7 +8080,9 @@ FAKE_F3: if (KB_KeyPressed(sc_F5) && MusicDevice >= 0) { KB_ClearKeyDown(sc_F5); - Bstrcpy(fta_quotes[26],&music_fn[0][(unsigned char)music_select][0]); + if (music_fn[0][(unsigned char)music_select] != NULL) + Bstrcpy(fta_quotes[26],&music_fn[0][(unsigned char)music_select][0]); + else fta_quotes[26][0] = '\0'; Bstrcat(fta_quotes[26],". USE SHIFT-F5 TO CHANGE."); FTA(26,&ps[myconnectindex]); } diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 24eeb1450..267a01386 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -4400,7 +4400,7 @@ SKIPJIBS: break; } - if (levnume > MAXLEVELS-1 || levnume <0) + if (levnume > MAXLEVELS-1 || levnume < 0) { /* if(g_cmddebug&CMDDEBUG_COMPILE) @@ -6532,7 +6532,8 @@ good: { insptr++; music_select=*insptr++; - playmusic(&music_fn[ud.volume_number][(unsigned char)music_select][0]); + if (music_fn[ud.volume_number][(unsigned char)music_select] != NULL) + playmusic(&music_fn[ud.volume_number][(unsigned char)music_select][0]); break; } diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 6c71528e5..e13d85ab5 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -3974,7 +3974,10 @@ cheat_for_port_credits: else { if (ud.recstat != 2 && ps[myconnectindex].gm&MODE_GAME) - playmusic(&music_fn[0][(unsigned char)music_select][0]); + { + if (music_fn[0][(unsigned char)music_select] != NULL) + playmusic(&music_fn[0][(unsigned char)music_select][0]); + } else playmusic(&env_music_fn[0][0]); MUSIC_Continue(); diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 2c7ee17e7..2417edd5a 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1750,7 +1750,8 @@ int enterlevel(char g) if (ud.recstat != 2) { music_select = (ud.volume_number*MAXLEVELS) + ud.level_number; - playmusic(&music_fn[0][(unsigned char)music_select][0]); + if (music_fn[0][(unsigned char)music_select] != NULL) + playmusic(&music_fn[0][(unsigned char)music_select][0]); } if ((g&MODE_GAME) || (g&MODE_EOL)) diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 57a95d321..ea13024de 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -354,7 +354,8 @@ int loadplayer(signed char spot) cacheit(); music_select = (ud.volume_number*MAXLEVELS) + ud.level_number; - playmusic(&music_fn[0][(unsigned char)music_select][0]); + if (music_fn[0][(unsigned char)music_select] != NULL) + playmusic(&music_fn[0][(unsigned char)music_select][0]); ps[myconnectindex].gm = MODE_GAME; ud.recstat = 0; diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index 04da73f0a..7b8df62be 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -208,6 +208,8 @@ void playmusic(char *fn) short fp; long l; + if (fn == NULL) return; + if (MusicToggle == 0) return; if (MusicDevice < 0) return; @@ -228,6 +230,8 @@ void playmusic(char *fn) #else void PlayMusic(char *_filename); + if (fn == NULL) return; + if(MusicToggle == 0) return; if(MusicDevice < 0) return;