From: Jean-Philippe André Date: Sun, 17 Jan 2010 15:35:10 +0000 (+0100) Subject: Audio output: fix integer overflow X-Git-Tag: 1.1.0-ff~1147 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=96e872ee848edad188d0b94d7df085fceeadd7ce;p=vlc Audio output: fix integer overflow This fixes the following bug: When scrolling the mouse wheel down, volume jumps from 0% to 400%. --- diff --git a/src/audio_output/intf.c b/src/audio_output/intf.c index db55c4ade4..b924904e65 100644 --- a/src/audio_output/intf.c +++ b/src/audio_output/intf.c @@ -76,7 +76,7 @@ int doVolumeChanges( unsigned action, vlc_object_t * p_object, int i_nb_steps, bool b_mute ) { int i_result = VLC_SUCCESS; - int i_volume_step = 1; + int i_volume_step = 1, i_new_volume = 0; bool b_var_mute = false; aout_instance_t *p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT, FIND_ANYWHERE ); @@ -120,12 +120,16 @@ int doVolumeChanges( unsigned action, vlc_object_t * p_object, int i_nb_steps, if ( !b_unmute_condition ) i_volume = config_GetInt( p_object, "volume" ); - i_volume += i_volume_step * i_nb_steps; - if ( i_volume > AOUT_VOLUME_MAX ) + i_new_volume = (int) i_volume + i_volume_step * i_nb_steps; + + if ( i_new_volume > AOUT_VOLUME_MAX ) i_volume = AOUT_VOLUME_MAX; - else if ( i_volume < AOUT_VOLUME_MIN ) + else if ( i_new_volume < AOUT_VOLUME_MIN ) i_volume = AOUT_VOLUME_MIN; + else + i_volume = i_new_volume; + if ( i_return_volume != NULL ) *i_return_volume = i_volume; }