diff --git a/code/client/snd_mix.c b/code/client/snd_mix.c index 7dbcfda33..cd8ea49c9 100644 --- a/code/client/snd_mix.c +++ b/code/client/snd_mix.c @@ -284,6 +284,9 @@ void S_SetVoiceAmplitudeFrom16( const sfx_t *sc, int sampleOffset, int count, in for ( i = 0; i < count; i++ ) { if ( sampleOffset >= SND_CHUNK_SIZE ) { chunk = chunk->next; + if ( !chunk ) { + chunk = sc->soundData; + } samples = chunk->sndChunk; sampleOffset = 0; } @@ -528,6 +531,9 @@ static void S_PaintChannelFrom16_scalar( channel_t *ch, const sfx_t *sc, int cou if (sampleOffset == SND_CHUNK_SIZE) { chunk = chunk->next; + if ( !chunk ) { + chunk = sc->soundData; + } samples = chunk->sndChunk; sampleOffset = 0; } @@ -703,6 +709,9 @@ void S_PaintChannelFromMuLaw( channel_t *ch, sfx_t *sc, int count, int sampleOff samples++; if (chunk != NULL && samples == (byte *)chunk->sndChunk+(SND_CHUNK_SIZE*2)) { chunk = chunk->next; + if ( !chunk ) { + chunk = sc->soundData; + } samples = (byte *)chunk->sndChunk; } } diff --git a/code/qcommon/common.c b/code/qcommon/common.c index 04f0e03f0..c341a1eea 100644 --- a/code/qcommon/common.c +++ b/code/qcommon/common.c @@ -624,8 +624,18 @@ Com_StringContains */ char *Com_StringContains( char *str1, char *str2, int casesensitive ) { int len, i, j; - - len = strlen( str1 ) - strlen( str2 ); + size_t l1, l2; + + l1 = strlen( str1 ); + l2 = strlen( str2 ); + if ( l2 > l1 ) { + // substring is longer than haystack; the loop below would + // not execute, but the unsigned subtraction would underflow + // before being truncated into int and produce indeterminate + // loop bounds. Bail explicitly. + return NULL; + } + len = (int)( l1 - l2 ); for ( i = 0; i <= len; i++, str1++ ) { for ( j = 0; str2[j]; j++ ) { if ( casesensitive ) {