diff options
author | Taylor <taylor.holberton@protonmail.com> | 2021-11-04 00:08:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-04 00:08:22 -0400 |
commit | 3f712873812610206d8eeb25d6df7cb3758811d5 (patch) | |
tree | 6f7b782f0dfc64b5c5b0cf37c7983988015fb19d /src | |
parent | 9109c94f269102785c606bd6c211b52fbbcd822d (diff) | |
parent | b49414ea5da073042aab753a4fd9fd05fa5bb8d5 (diff) |
Merge pull request #218 from aospm/index-underflow
mixer: fix index underflow when index=0
Diffstat (limited to 'src')
-rw-r--r-- | src/mixer.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/mixer.c b/src/mixer.c index 5581e5d..b4d96fd 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -732,9 +732,13 @@ struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer, ctl = grp->ctl; for (n = 0; n < grp->count; n++) - if (!strcmp(name, (char*) ctl[n].info.id.name)) - if (index-- == 0) + if (!strcmp(name, (char*) ctl[n].info.id.name)) { + if (index == 0) { return ctl + n; + } else { + index--; + } + } } #ifdef TINYALSA_USES_PLUGINS @@ -743,9 +747,13 @@ struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer, ctl = grp->ctl; for (n = 0; n < grp->count; n++) - if (!strcmp(name, (char*) ctl[n].info.id.name)) - if (index-- == 0) + if (!strcmp(name, (char*) ctl[n].info.id.name)) { + if (index == 0) { return ctl + n; + } else { + index--; + } + } } #endif return NULL; |