From 16cb06c99f78a21b1be2bc681c1f1d85a6caddca Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 10 Sep 2021 22:59:51 +0100 Subject: [PATCH] Fix bad channel count handling with libsamplerate 0.2.0 Since libsndfile/libsamplerate@26d92c369394bcd0b0cea488890edce1a0d757d5, initialising libsamplerate with 0 channels or less causes a SIGABRT. We therefore need to handle this in the C++ wrapper classes. --- libs/libsamplerate/include/samplerate.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/libsamplerate/include/samplerate.hpp b/libs/libsamplerate/include/samplerate.hpp index d0af34317..23e243d91 100644 --- a/libs/libsamplerate/include/samplerate.hpp +++ b/libs/libsamplerate/include/samplerate.hpp @@ -152,6 +152,8 @@ class State : public detail::StateBase { static SRC_STATE* createOrThrow(Converter converter, int channels) { + if (channels <= 0) + throw std::runtime_error("Channel count must be >= 1."); int error; auto* state = src_new(static_cast(converter), channels, &error); if(!state) @@ -174,6 +176,8 @@ class StateCallback : public detail::StateBase { static SRC_STATE* createOrThrow(Converter converter, int channels, src_callback_t func, void* data) { + if (channels <= 0) + throw std::runtime_error("Channel count must be >= 1."); int error; auto* state = src_callback_new(func, static_cast(converter), channels, &error, data); if(!state) -- 2.32.0