From: Jaroslav Kysela Date: Thu, 23 May 2024 11:13:42 +0000 (+0200) Subject: alsamixer: fix calculation in set_normalized_volume (overflow) X-Git-Tag: v1.2.12~4 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=84d0a91f11678096d30b28fed46d396d5b28388e;p=alsa-utils.git alsamixer: fix calculation in set_normalized_volume (overflow) Lowering volume below 0 causes overflow spike to 100% volume (volume goes below 0 and back to 100 repeatedly). 0 overflows past infinity when holding down z,x,c. > value = lrint_dir(6000.0 * log10(volume), dir) + max; (where volume = 0 , and dir = -1 . min = -9999999 , and max = -6) > log10(0) is negative infinity = error Fixes: https://github.com/alsa-project/alsa-utils/pull/266 Reported-by: genr8eofl Signed-off-by: Jaroslav Kysela --- diff --git a/alsamixer/volume_mapping.c b/alsamixer/volume_mapping.c index 29ab061..f34801c 100644 --- a/alsamixer/volume_mapping.c +++ b/alsamixer/volume_mapping.c @@ -146,6 +146,8 @@ static int set_normalized_volume(snd_mixer_elem_t *elem, min_norm = pow(10, (min - max) / 6000.0); volume = volume * (1 - min_norm) + min_norm; } + if (volume <= 0) + volume = 1e-36; value = lrint_dir(6000.0 * log10(volume), dir) + max; return set_dB[ctl_dir](elem, channel, value, dir); }