]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsactl: init - set_ctl_value() - fix bytes parsing
authorJaroslav Kysela <perex@perex.cz>
Fri, 8 Jan 2021 17:15:43 +0000 (18:15 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 8 Jan 2021 17:16:14 +0000 (18:16 +0100)
Use the correct error value handling from hextodigit().

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
alsactl/init_parse.c

index ee9cc6d8f1b1b19eaed13f445014bc693a433ddd..58b46f42de4bf9d2d206580800663c92dd5488a3 100644 (file)
@@ -465,12 +465,13 @@ static int set_ctl_value(struct space *space, const char *value, int all)
                        return -EINVAL;
                }
                for (idx = 0; idx < count; idx += 2) {
-                       val = hextodigit(*(value++)) << 4;
-                       val |= hextodigit(*(value++));
-                       if (val > 255) {
+                       int nibble1 = hextodigit(*(value++));
+                       int nibble2 = hextodigit(*(value++));
+                       if (nibble1 < 0 || nibble2 < 0) {
                                Perror(space, "bad ctl hexa value");
                                return -EINVAL;
                        }
+                       val = (nibble1 << 4) | nibble2;
                        snd_ctl_elem_value_set_byte(space->ctl_value, idx, val);
                }
                break;