From c9b86f49a8a1a8c337bf0c1b7f12749e8be781ed Mon Sep 17 00:00:00 2001 From: Clemens Ladisch Date: Mon, 22 Feb 2010 09:42:03 +0100 Subject: alsamixer: handle out-of-range volume values Ensure that control volume values are in their allowed range; otherwise, the displayed values could be outside the range 0..100 and mess up the layout. Signed-off-by: Clemens Ladisch --- alsamixer/mixer_display.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/alsamixer/mixer_display.c b/alsamixer/mixer_display.c index 260c9b0..20d6d6a 100644 --- a/alsamixer/mixer_display.c +++ b/alsamixer/mixer_display.c @@ -390,6 +390,15 @@ static void display_string_centered_in_control(int y, int col, const char *s, in display_string_in_field(y, x, s, width, ALIGN_CENTER); } +static long clamp(long value, long min, long max) +{ + if (value < min) + return min; + if (value > max) + return max; + return value; +} + static void display_control(unsigned int control_index) { struct control *control; @@ -462,8 +471,10 @@ static void display_control(unsigned int control_index) err = snd_mixer_selem_get_capture_volume_range(control->elem, &min, &max); if (err < 0) return; - if (min == max) + if (min >= max) max = min + 1; + volumes[0] = clamp(volumes[0], min, max); + volumes[1] = clamp(volumes[1], min, max); if (control->flags & IS_ACTIVE) wattrset(mixer_widget.window, 0); -- cgit v1.2.1