mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-21 08:56: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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2463,7 +2463,7 @@ int pa__init(pa_module *m) {
|
|||
|
||||
channels = u->sample_spec.channels;
|
||||
if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 ||
|
||||
channels <= 0 || channels > PA_CHANNELS_MAX) {
|
||||
!pa_channels_valid(channels)) {
|
||||
pa_log_error("Failed to get channels from module arguments");
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -350,8 +350,7 @@ int pa__init(pa_module*m) {
|
|||
channels = m->core->default_sample_spec.channels;
|
||||
|
||||
if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 ||
|
||||
channels <= 0 ||
|
||||
channels > PA_CHANNELS_MAX) {
|
||||
!pa_channels_valid(channels)) {
|
||||
pa_log("Failed to parse channels= argument.");
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,8 +297,7 @@ int pa__init(pa_module*m) {
|
|||
channels = m->core->default_sample_spec.channels;
|
||||
|
||||
if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 ||
|
||||
channels <= 0 ||
|
||||
channels >= PA_CHANNELS_MAX) {
|
||||
!pa_channels_valid(channels)) {
|
||||
pa_log("failed to parse channels= argument.");
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ int pa__init(pa_module *m) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (pa_modargs_get_value_u32(ma, "channels", &u->channels) < 0 || u->channels > PA_CHANNELS_MAX) {
|
||||
if (pa_modargs_get_value_u32(ma, "channels", &u->channels) < 0 || !pa_channels_valid(u->channels)) {
|
||||
pa_log("Failed to parse channels= argument.");
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue