mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
Add pa_channels_valid()
I think this makes the code a bit nicer to read and write. This also reduces the chances of off-by-one errors when checking the bounds of channel count values.
This commit is contained in:
parent
a67318f8af
commit
2747c96101
12 changed files with 24 additions and 22 deletions
|
|
@ -214,7 +214,7 @@ static int ucm_get_device_property(
|
|||
value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_PLAYBACK_CHANNELS);
|
||||
if (value) { /* output */
|
||||
/* get channels */
|
||||
if (pa_atou(value, &ui) == 0 && ui < PA_CHANNELS_MAX)
|
||||
if (pa_atou(value, &ui) == 0 && pa_channels_valid(ui))
|
||||
device->playback_channels = ui;
|
||||
else
|
||||
pa_log("UCM playback channels %s for device %s out of range", value, device_name);
|
||||
|
|
@ -234,7 +234,7 @@ static int ucm_get_device_property(
|
|||
value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_CAPTURE_CHANNELS);
|
||||
if (value) { /* input */
|
||||
/* get channels */
|
||||
if (pa_atou(value, &ui) == 0 && ui < PA_CHANNELS_MAX)
|
||||
if (pa_atou(value, &ui) == 0 && pa_channels_valid(ui))
|
||||
device->capture_channels = ui;
|
||||
else
|
||||
pa_log("UCM capture channels %s for device %s out of range", value, device_name);
|
||||
|
|
@ -1128,7 +1128,7 @@ static void alsa_mapping_add_ucm_modifier(pa_alsa_mapping *m, pa_alsa_ucm_modifi
|
|||
/* FIXME: channel_str is unsanitized input from the UCM configuration,
|
||||
* we should do proper error handling instead of asserting.
|
||||
* https://bugs.freedesktop.org/show_bug.cgi?id=71823 */
|
||||
pa_assert_se(pa_atou(channel_str, &channels) == 0 && channels < PA_CHANNELS_MAX);
|
||||
pa_assert_se(pa_atou(channel_str, &channels) == 0 && pa_channels_valid(channels));
|
||||
pa_log_debug("Got channel count %" PRIu32 " for modifier", channels);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue