From d83ff6360790269f3ce407a0b39c9279efc66b8c Mon Sep 17 00:00:00 2001 From: helixhorned Date: Tue, 10 Jan 2012 23:44:49 +0000 Subject: [PATCH] sounds.c: check the sound number before accessing arrays with it; always do this in "(unsigned)i < bound" fashion. git-svn-id: https://svn.eduke32.com/eduke32@2245 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/sounds.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index cb9e83179..d05e40def 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -351,7 +351,7 @@ int32_t S_LoadSound(uint32_t num) { int32_t fp = -1, l; - if ((int32_t)num > g_maxSoundPos || ud.config.SoundToggle == 0 || ud.config.FXDevice < 0) return 0; + if (num > (unsigned)g_maxSoundPos || ud.config.SoundToggle == 0 || ud.config.FXDevice < 0) return 0; if (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL) { @@ -385,7 +385,7 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos) int32_t cs; int32_t voice, sndang, ca, pitch; - if (num > g_maxSoundPos || + if ((unsigned)num > (unsigned)g_maxSoundPos || ud.config.FXDevice < 0 || ((g_sounds[num].m&8) && ud.lockout) || ud.config.SoundToggle == 0 || @@ -548,14 +548,16 @@ int32_t S_PlaySound(int32_t num) if (ud.config.FXDevice < 0) return -1; if (ud.config.SoundToggle==0) return -1; if (!(ud.config.VoiceToggle&1) && (g_sounds[num].m&4)) return -1; - if ((g_sounds[num].m&8) && ud.lockout) return -1; - if (FX_VoiceAvailable(g_sounds[num].pr) == 0) return -1; - if (num > g_maxSoundPos || (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL)) + + if ((unsigned)num > (unsigned)g_maxSoundPos || (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL)) { OSD_Printf("WARNING: invalid sound #%d\n",num); return -1; } + if ((g_sounds[num].m&8) && ud.lockout) return -1; + if (FX_VoiceAvailable(g_sounds[num].pr) == 0) return -1; + pitch = (cx = klabs(g_sounds[num].pe-g_sounds[num].ps)) ? (g_sounds[num].ps < g_sounds[num].pe ? g_sounds[num].ps : g_sounds[num].pe) + rand()%cx : g_sounds[num].ps;