summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-core-ctl.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-16 11:24:04 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-17 09:12:30 +0100
commite28d3210846d1984f8cda79f8b556a731690627d (patch)
tree184b0bbcb0f52213d6aa66825d80890dc40e3929 /plugins/alsa/alsa-core-ctl.c
parent739ff0e0de5ed0a921395dd24b882d795123be30 (diff)
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 <jonathan.aillet@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-core-ctl.c')
-rw-r--r--plugins/alsa/alsa-core-ctl.c14
1 files changed, 14 insertions, 0 deletions
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);
}