Added a bunch of channel bounds error checking
authorSam Lantinga <slouken@libsdl.org>
Wed, 12 Jan 2011 18:12:28 -0800
changeset 492e9ae8f659fea
parent 491 0f6c89f20c76
child 493 ff616dc8d6c3
Added a bunch of channel bounds error checking
mixer.c
     1.1 --- a/mixer.c	Tue Jan 11 01:29:19 2011 -0800
     1.2 +++ b/mixer.c	Wed Jan 12 18:12:28 2011 -0800
     1.3 @@ -820,7 +820,7 @@
     1.4  		}
     1.5  
     1.6  		/* Queue up the audio data for this channel */
     1.7 -		if ( which >= 0 ) {
     1.8 +		if ( which >= 0 && which < num_channels ) {
     1.9  			Uint32 sdl_ticks = SDL_GetTicks();
    1.10  			if (Mix_Playing(which))
    1.11  				_Mix_channel_done_playing(which);
    1.12 @@ -890,7 +890,7 @@
    1.13  		}
    1.14  
    1.15  		/* Queue up the audio data for this channel */
    1.16 -		if ( which >= 0 ) {
    1.17 +		if ( which >= 0 && which < num_channels ) {
    1.18  			Uint32 sdl_ticks = SDL_GetTicks();
    1.19  			if (Mix_Playing(which))
    1.20  				_Mix_channel_done_playing(which);
    1.21 @@ -918,15 +918,14 @@
    1.22  int Mix_Volume(int which, int volume)
    1.23  {
    1.24  	int i;
    1.25 -	int prev_volume;
    1.26 +	int prev_volume = 0;
    1.27  
    1.28  	if ( which == -1 ) {
    1.29 -		prev_volume = 0;
    1.30  		for ( i=0; i<num_channels; ++i ) {
    1.31  			prev_volume += Mix_Volume(i, volume);
    1.32  		}
    1.33  		prev_volume /= num_channels;
    1.34 -	} else {
    1.35 +	} else if ( which < num_channels ) {
    1.36  		prev_volume = mix_channel[which].volume;
    1.37  		if ( volume >= 0 ) {
    1.38  			if ( volume > SDL_MIX_MAXVOLUME ) {
    1.39 @@ -961,7 +960,7 @@
    1.40  		for ( i=0; i<num_channels; ++i ) {
    1.41  			Mix_HaltChannel(i);
    1.42  		}
    1.43 -	} else {
    1.44 +	} else if ( which < num_channels ) {
    1.45  		SDL_LockAudio();
    1.46  		if (mix_channel[which].playing) {
    1.47  			_Mix_channel_done_playing(which);
    1.48 @@ -1002,7 +1001,7 @@
    1.49  			for ( i=0; i<num_channels; ++i ) {
    1.50  				status += Mix_FadeOutChannel(i, ms);
    1.51  			}
    1.52 -		} else {
    1.53 +		} else if ( which < num_channels ) {
    1.54  			SDL_LockAudio();
    1.55  			if ( mix_channel[which].playing && 
    1.56  			    (mix_channel[which].volume > 0) &&
    1.57 @@ -1039,6 +1038,9 @@
    1.58  
    1.59  Mix_Fading Mix_FadingChannel(int which)
    1.60  {
    1.61 +	if ( which < 0 || which >= num_channels ) {
    1.62 +		return MIX_NO_FADING;
    1.63 +	}
    1.64  	return mix_channel[which].fading;
    1.65  }
    1.66  
    1.67 @@ -1060,9 +1062,9 @@
    1.68  				++status;
    1.69  			}
    1.70  		}
    1.71 -	} else {
    1.72 -		if ((mix_channel[which].playing > 0) ||
    1.73 -			(mix_channel[which].looping > 0))
    1.74 +	} else if ( which < num_channels ) {
    1.75 +		if ( (mix_channel[which].playing > 0) ||
    1.76 +		     (mix_channel[which].looping > 0) )
    1.77  		{
    1.78  			++status;
    1.79  		}
    1.80 @@ -1121,7 +1123,7 @@
    1.81  				mix_channel[i].paused = sdl_ticks;
    1.82  			}
    1.83  		}
    1.84 -	} else {
    1.85 +	} else if ( which < num_channels ) {
    1.86  		if ( mix_channel[which].playing > 0 ) {
    1.87  			mix_channel[which].paused = sdl_ticks;
    1.88  		}
    1.89 @@ -1144,7 +1146,7 @@
    1.90  				mix_channel[i].paused = 0;
    1.91  			}
    1.92  		}
    1.93 -	} else {
    1.94 +	} else if ( which < num_channels ) {
    1.95  		if ( mix_channel[which].playing > 0 ) {
    1.96  			if(mix_channel[which].expire > 0)
    1.97  				mix_channel[which].expire += sdl_ticks - mix_channel[which].paused;
    1.98 @@ -1156,8 +1158,6 @@
    1.99  
   1.100  int Mix_Paused(int which)
   1.101  {
   1.102 -	if ( which > num_channels )
   1.103 -		return(0);
   1.104  	if ( which < 0 ) {
   1.105  		int status = 0;
   1.106  		int i;
   1.107 @@ -1167,8 +1167,10 @@
   1.108  			}
   1.109  		}
   1.110  		return(status);
   1.111 +	} else if ( which < num_channels ) {
   1.112 +		return(mix_channel[which].paused != 0);
   1.113  	} else {
   1.114 -		return(mix_channel[which].paused != 0);
   1.115 +		return(0);
   1.116  	}
   1.117  }
   1.118