mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-11 13:30:02 -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
|
|
@ -111,12 +111,15 @@ int pa_sample_rate_valid(uint32_t rate) {
|
|||
return rate > 0 && rate <= PA_RATE_MAX;
|
||||
}
|
||||
|
||||
int pa_channels_valid(uint8_t channels) {
|
||||
return channels > 0 && channels <= PA_CHANNELS_MAX;
|
||||
}
|
||||
|
||||
int pa_sample_spec_valid(const pa_sample_spec *spec) {
|
||||
pa_assert(spec);
|
||||
|
||||
if (PA_UNLIKELY(!pa_sample_rate_valid(spec->rate) ||
|
||||
spec->channels <= 0 ||
|
||||
spec->channels > PA_CHANNELS_MAX ||
|
||||
!pa_channels_valid(spec->channels) ||
|
||||
!pa_sample_format_valid(spec->format)))
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue