From e28d3210846d1984f8cda79f8b556a731690627d Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Wed, 16 Jan 2019 11:24:04 +0100 Subject: Prevents setting of ALSA controls out-of-range Prevents setting of ALSA control values out-of-range for INTEGER type controls. Change-Id: I7f1ef24b50022df844f6916489e0f45680de6126 Signed-off-by: Jonathan Aillet --- plugins/alsa/alsa-core-ctl.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/alsa/alsa-core-ctl.c b/plugins/alsa/alsa-core-ctl.c index 020c13c..e747090 100644 --- a/plugins/alsa/alsa-core-ctl.c +++ b/plugins/alsa/alsa-core-ctl.c @@ -232,6 +232,7 @@ PUBLIC int CtlElemIdSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, snd_ctl_ele snd_ctl_elem_info_t *elemInfo; const char* name; int error, numid; + long min, max; snd_ctl_elem_info_alloca(&elemInfo); snd_ctl_elem_info_set_id(elemInfo, elemId); @@ -247,6 +248,19 @@ PUBLIC int CtlElemIdSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, snd_ctl_ele error = snd_ctl_elem_read(sndcard->ctl, elemData); if (error) goto OnErrorExit; + switch(snd_ctl_elem_info_get_type(elemInfo)) { + case SND_CTL_ELEM_TYPE_INTEGER: + min = snd_ctl_elem_info_get_min(elemInfo); + max = snd_ctl_elem_info_get_max(elemInfo); + + value = (value < min) ? min : value; + value = (value > max) ? max : value; + break; + + default: + break; + } + for (int index = 0; index < count; index++) { snd_ctl_elem_value_set_integer(elemData, index, value); } -- cgit 1.2.3-korg