From e86e95feabb3002c4f07624d9491b96522c0db32 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sat, 25 Jul 2026 18:50:40 -0400 Subject: [PATCH] DATV: Convert leansdr fail and fatal errors into C++ exceptions The original leansdr code uses fatal() and fail() for unrecoverable errors by terminating execution. When integrated into SDRangel, these error paths did not provide a mechanism for the plugin to handle failures locally, allowing initialization failures to escape the normal plugin lifecycle. Convert leansdr fatal() and fail() handling into C++ exceptions so DATV can detect framework initialization failures, report them, and cleanly return control to SDRangel instead of allowing the error to terminate the application. This behavior is desirable because a DATV framework configuration failure should not bring down the entire application. Catch initialization exceptions in DATVDemodSink::feed(), report the failure, clean up the partially initialized framework, and return to the caller. Add noreturn annotations to the leansdr error functions and include the leansdr source in exception messages to make failures easier to diagnose. This does not redesign leansdr error handling or provide recovery from runtime DSP failures. It only adds an exception boundary between the leansdr library code and the SDRangel plugin lifecycle. noticed via cppcheck indicating many Array indexes could go out of bounds due to fail and fatal returning. Signed-off-by: Robin Getz --- plugins/channelrx/demoddatv/datvdemodsink.cpp | 26 ++++++++++++++----- .../channelrx/demoddatv/leansdr/framework.cpp | 12 ++++++--- .../channelrx/demoddatv/leansdr/framework.h | 4 +-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/plugins/channelrx/demoddatv/datvdemodsink.cpp b/plugins/channelrx/demoddatv/datvdemodsink.cpp index 0ba3033e9..7d29a2f8f 100644 --- a/plugins/channelrx/demoddatv/datvdemodsink.cpp +++ b/plugins/channelrx/demoddatv/datvdemodsink.cpp @@ -1281,16 +1281,28 @@ void DATVDemodSink::feed(const SampleVector::const_iterator& begin, const Sample qDebug("DATVDemodSink::feed: Settings applied. Standard : %d...", m_settings.m_standard); m_blnNeedConfigUpdate = false; - - if(m_settings.m_standard==DATVDemodSettings::DVB_S2) + try { - qDebug("DATVDemodSink::feed: init DVBS-2"); - InitDATVS2Framework(); + if(m_settings.m_standard==DATVDemodSettings::DVB_S2) + { + qDebug("DATVDemodSink::feed: init DVBS-2"); + InitDATVS2Framework(); + } + else + { + qDebug("DATVDemodSink::feed: init DVBS"); + InitDATVFramework(); + } } - else + catch (const std::exception& e) { - qDebug("DATVDemodSink::feed: init DVBS"); - InitDATVFramework(); + // leansdr uses fail() for unrecoverable internal errors. + // Convert these into a DATV initialization failure instead of + // allowing them to terminate the application. + qCritical("DATVDemodSink::feed: DATV framework initialization failed: %s", e.what()); + + CleanUpDATVFramework(); + return; } } diff --git a/plugins/channelrx/demoddatv/leansdr/framework.cpp b/plugins/channelrx/demoddatv/leansdr/framework.cpp index f2db59ec5..a7bf416b5 100644 --- a/plugins/channelrx/demoddatv/leansdr/framework.cpp +++ b/plugins/channelrx/demoddatv/leansdr/framework.cpp @@ -14,17 +14,23 @@ // You should have received a copy of the GNU General Public License // // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////////// + +#include +#include + #include "framework.h" namespace leansdr { -void fatal(const char *s) { +[[noreturn]] void fatal(const char *s) { perror(s); + throw std::runtime_error(std::string("leansdr fatal: ") + s); } -void fail(const char *s) { - fprintf(stderr, "** %s\n", s); +[[noreturn]] void fail(const char *s) { + fprintf(stderr, "** leansdr fail: %s\n", s); + throw std::runtime_error(std::string("leansdr fail: ") + s); } } // leansdr diff --git a/plugins/channelrx/demoddatv/leansdr/framework.h b/plugins/channelrx/demoddatv/leansdr/framework.h index ffa7a5559..0ebb7bd90 100644 --- a/plugins/channelrx/demoddatv/leansdr/framework.h +++ b/plugins/channelrx/demoddatv/leansdr/framework.h @@ -35,8 +35,8 @@ namespace leansdr { -void fatal(const char *s); -void fail(const char *s); +[[noreturn]] void fatal(const char *s); +[[noreturn]] void fail(const char *s); ////////////////////////////////////////////////////////////////////// // DSP framework