summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2015-05-01 21:50:03 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2015-05-01 21:50:03 -0300
commit7ff651d9a6380790a838e000c06f76224085c636 (patch)
treea88c3f6609b00198ce159cd762b2e2d4c560a816
parent3956a58164084b6959046929707afc52fe31de5e (diff)
module: Avoid division by zero
-rw-r--r--src/module/e_mod_main.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/module/e_mod_main.c b/src/module/e_mod_main.c
index 828b148..6adc20f 100644
--- a/src/module/e_mod_main.c
+++ b/src/module/e_mod_main.c
@@ -155,7 +155,8 @@ _mixer_gadget_update(void)
155 for (i = 0; i < 155 for (i = 0; i <
156 mixer_context->sink_default->volume.channel_count; i++) 156 mixer_context->sink_default->volume.channel_count; i++)
157 vol += mixer_context->sink_default->volume.volumes[i]; 157 vol += mixer_context->sink_default->volume.volumes[i];
158 vol /= mixer_context->sink_default->volume.channel_count; 158 if (mixer_context->sink_default->volume.channel_count)
159 vol /= mixer_context->sink_default->volume.channel_count;
159 msg->val[0] = mixer_context->sink_default->mute; 160 msg->val[0] = mixer_context->sink_default->mute;
160 msg->val[1] = vol; 161 msg->val[1] = vol;
161 msg->val[2] = msg->val[1]; 162 msg->val[2] = msg->val[1];
@@ -369,16 +370,17 @@ static Evas_Object *
369_popup_add_slider(void) 370_popup_add_slider(void)
370{ 371{
371 unsigned int volume, i; 372 unsigned int volume, i;
373 unsigned int channels = mixer_context->sink_default->volume.channel_count;
372 374
373 Evas_Object *slider = elm_slider_add(e_comp->elm); 375 Evas_Object *slider = elm_slider_add(e_comp->elm);
374 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL); 376 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
375 evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0); 377 evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
376 378
377 for (volume = 0, i = 0; i < 379 for (volume = 0, i = 0; i < channels; i++)
378 mixer_context->sink_default->volume.channel_count; i++)
379 volume += mixer_context->sink_default->volume.volumes[i]; 380 volume += mixer_context->sink_default->volume.volumes[i];
380 381
381 volume = volume / i; 382 if (channels)
383 volume = volume / channels;
382 384
383 evas_object_show(slider); 385 evas_object_show(slider);
384 elm_slider_min_max_set(slider, 0.0, (double) EMIX_VOLUME_MAX); 386 elm_slider_min_max_set(slider, 0.0, (double) EMIX_VOLUME_MAX);