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 --- src/pulse/sample.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pulse/sample.c b/src/pulse/sample.c index 1331c72..cb04254 100644 --- a/src/pulse/sample.c +++ b/src/pulse/sample.c @@ -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); } -- 2.7.4