From e4c1d0e7c87eee53a8cdf3f044527de31639f186 Mon Sep 17 00:00:00 2001 From: nukeykt Date: Thu, 14 Nov 2019 04:28:17 +0900 Subject: [PATCH] Add checks for invalid sound that can cause crash --- source/exhumed/src/sound.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source/exhumed/src/sound.cpp b/source/exhumed/src/sound.cpp index 098eb2de0..b6d382337 100644 --- a/source/exhumed/src/sound.cpp +++ b/source/exhumed/src/sound.cpp @@ -821,7 +821,7 @@ void UpdateSounds() void UpdateCreepySounds() { - if (levelnum == 20) + if (levelnum == 20 || nFreeze) return; spritetype *pSprite = &sprite[PlayerList[nLocalPlayer].nSprite]; nCreepyTimer--; @@ -893,6 +893,12 @@ void PlaySound(int nSound) if (!dig) return; + if (nSound < 0 || nSound >= kMaxSounds || !SoundBuf[nSound]) + { + initprintf("PlaySound: Invalid sound nSound == %i\n", nSound); + return; + } + int bLoop = SoundBuf[nSound][26] == 6; if (handle >= 0) @@ -917,6 +923,12 @@ void PlayLocalSound(short nSound, short nRate) if (!dig) return; + if (nSound < 0 || nSound >= kMaxSounds || !SoundBuf[nSound]) + { + initprintf("PlayLocalSound: Invalid sound nSound == %i, nRate == %i\n", nSound, nRate); + return; + } + if (nLocalChan == nAmbientChannel) nAmbientChannel = -1; @@ -974,6 +986,12 @@ short PlayFX2(unsigned short nSound, short nSprite) if (!dig) return -1; + if (nSound < 0 || nSound >= kMaxSounds || !SoundBuf[nSound]) + { + initprintf("PlayFX2: Invalid sound nSound == %i, nSprite == %i\n", nSound, nSprite); + return -1; + } + nLocalSectFlags = SectFlag[nPlayerViewSect[nLocalPlayer]]; short v1c; short vcx;