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:
Tanu Kaskinen 2013-12-04 09:50:11 +02:00 committed by Peter Meerwald
parent a67318f8af
commit 2747c96101
12 changed files with 24 additions and 22 deletions

View file

@ -73,8 +73,7 @@ pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) {
int i;
pa_assert(a);
pa_assert(channels > 0);
pa_assert(channels <= PA_CHANNELS_MAX);
pa_assert(pa_channels_valid(channels));
a->channels = (uint8_t) channels;
@ -533,7 +532,7 @@ int pa_cvolume_valid(const pa_cvolume *v) {
pa_assert(v);
if (v->channels <= 0 || v->channels > PA_CHANNELS_MAX)
if (!pa_channels_valid(v->channels))
return 0;
for (c = 0; c < v->channels; c++)