mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
sample: Assert validity of sample_spec
passing an invalid sample_spec to pa_sample_size_of_format(), pa_frame_size(), pa_bytes_per_second(), pa_bytes_to_usec(), pa_usec_to_bytes() currently gives a result of 0 this is problematic as (a) it leads to many potential divide-by-zero issues flagged by Coverity, (b) pa_sample_spec_valid() is called often and the mostly unnecessary validation of the sample_spec cannot be optimized away due to pa_return_val_if_fail() (c) nobody checks the result for 0 and the behaviour is not documented this patch replaces pa_return_val_if_fail() with pa_assert() note that this commit changes the API! note that pa_return_val_if_fail() strangely logs an assertion, but then happily continues... fixes numerious CIDs
This commit is contained in:
parent
250fd43bdc
commit
83f0a34ea6
1 changed files with 5 additions and 6 deletions
|
|
@ -56,37 +56,36 @@ size_t pa_sample_size_of_format(pa_sample_format_t f) {
|
|||
}
|
||||
|
||||
size_t pa_sample_size(const pa_sample_spec *spec) {
|
||||
|
||||
pa_assert(spec);
|
||||
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
|
||||
pa_assert(pa_sample_spec_valid(spec));
|
||||
|
||||
return size_table[spec->format];
|
||||
}
|
||||
|
||||
size_t pa_frame_size(const pa_sample_spec *spec) {
|
||||
pa_assert(spec);
|
||||
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
|
||||
pa_assert(pa_sample_spec_valid(spec));
|
||||
|
||||
return size_table[spec->format] * spec->channels;
|
||||
}
|
||||
|
||||
size_t pa_bytes_per_second(const pa_sample_spec *spec) {
|
||||
pa_assert(spec);
|
||||
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
|
||||
pa_assert(pa_sample_spec_valid(spec));
|
||||
|
||||
return spec->rate * size_table[spec->format] * spec->channels;
|
||||
}
|
||||
|
||||
pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) {
|
||||
pa_assert(spec);
|
||||
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
|
||||
pa_assert(pa_sample_spec_valid(spec));
|
||||
|
||||
return (((pa_usec_t) (length / (size_table[spec->format] * spec->channels)) * PA_USEC_PER_SEC) / spec->rate);
|
||||
}
|
||||
|
||||
size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) {
|
||||
pa_assert(spec);
|
||||
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
|
||||
pa_assert(pa_sample_spec_valid(spec));
|
||||
|
||||
return (size_t) (((t * spec->rate) / PA_USEC_PER_SEC)) * (size_table[spec->format] * spec->channels);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue