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
This commit is contained in:
helixhorned 2012-01-10 23:44:49 +00:00
parent 3095b09773
commit d83ff63607

View file

@ -351,7 +351,7 @@ int32_t S_LoadSound(uint32_t num)
{ {
int32_t fp = -1, l; 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) 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 cs;
int32_t voice, sndang, ca, pitch; int32_t voice, sndang, ca, pitch;
if (num > g_maxSoundPos || if ((unsigned)num > (unsigned)g_maxSoundPos ||
ud.config.FXDevice < 0 || ud.config.FXDevice < 0 ||
((g_sounds[num].m&8) && ud.lockout) || ((g_sounds[num].m&8) && ud.lockout) ||
ud.config.SoundToggle == 0 || 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.FXDevice < 0) return -1;
if (ud.config.SoundToggle==0) return -1; if (ud.config.SoundToggle==0) return -1;
if (!(ud.config.VoiceToggle&1) && (g_sounds[num].m&4)) 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 ((unsigned)num > (unsigned)g_maxSoundPos || (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL))
if (num > g_maxSoundPos || (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL))
{ {
OSD_Printf("WARNING: invalid sound #%d\n",num); OSD_Printf("WARNING: invalid sound #%d\n",num);
return -1; 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)) ? 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].ps < g_sounds[num].pe ? g_sounds[num].ps :
g_sounds[num].pe) + rand()%cx : g_sounds[num].ps; g_sounds[num].pe) + rand()%cx : g_sounds[num].ps;