From bb01f58f28290192f1169aaefe108fffea0bfee4 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sun, 2 Aug 2026 19:39:40 -0400 Subject: [PATCH] demodvormc: Fix uninitialized variable phase in radial calculation Coverity reported an uninitialized scalar use of varPhase when the reference and variable Goertzel filters completed at different times. Store the last valid variable phase and magnitude values to ensure the radial calculation always uses initialized data. Signed-off-by: Robin Getz --- plugins/channelrx/demodvormc/vordemodmcsink.cpp | 14 +++++++------- plugins/channelrx/demodvormc/vordemodmcsink.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/channelrx/demodvormc/vordemodmcsink.cpp b/plugins/channelrx/demodvormc/vordemodmcsink.cpp index dc9be4af7..2795174b1 100644 --- a/plugins/channelrx/demodvormc/vordemodmcsink.cpp +++ b/plugins/channelrx/demodvormc/vordemodmcsink.cpp @@ -44,6 +44,8 @@ VORDemodMCSink::VORDemodMCSink(const VORDemodMCSettings& settings, int subChanne m_volumeAGC(0.003), m_audioFifo(48000), m_refPrev(0.0f), + m_varPhase(0.0), + m_varMag(0.0), m_movingAverageIdent(5000), m_prevBit(0), m_bitTime(0), @@ -204,13 +206,11 @@ void VORDemodMCSink::processOneSample(Complex &ci) Real mag = std::sqrt(magsq); // Calculate phase of 30Hz variable AM signal - double varPhase; - double varMag; if (m_varGoertzel.size() == VORDEMOD_CHANNEL_SAMPLE_RATE - 1) { m_varGoertzel.goertzel(mag); - varPhase = Units::radiansToDegrees(m_varGoertzel.phase()); - varMag = m_varGoertzel.mag(); + m_varPhase = Units::radiansToDegrees(m_varGoertzel.phase()); + m_varMag = m_varGoertzel.mag(); m_varGoertzel.reset(); } else @@ -239,17 +239,17 @@ void VORDemodMCSink::processOneSample(Complex &ci) float shiftedPhase = phaseDeg + filterPhaseShift; // Calculate difference in phase, which is the radial - float phaseDifference = shiftedPhase - varPhase; + float phaseDifference = shiftedPhase - m_varPhase; if (phaseDifference < 0.0) phaseDifference += 360.0; else if (phaseDifference >= 360.0) phaseDifference -= 360.0; - // qDebug() << "Ref phase: " << phaseDeg << " var phase " << varPhase; + // qDebug() << "Ref phase: " << phaseDeg << " var phase " << m_varPhase; if (getMessageQueueToGUI()) { - VORDemodMCReport::MsgReportRadial *msg = VORDemodMCReport::MsgReportRadial::create(m_subChannelId, phaseDifference, refMag, varMag); + VORDemodMCReport::MsgReportRadial *msg = VORDemodMCReport::MsgReportRadial::create(m_subChannelId, phaseDifference, refMag, m_varMag); getMessageQueueToGUI()->push(msg); } diff --git a/plugins/channelrx/demodvormc/vordemodmcsink.h b/plugins/channelrx/demodvormc/vordemodmcsink.h index fb6228b87..287e4fdbf 100644 --- a/plugins/channelrx/demodvormc/vordemodmcsink.h +++ b/plugins/channelrx/demodvormc/vordemodmcsink.h @@ -132,6 +132,8 @@ private: Lowpass m_lowpassRef; Lowpass m_lowpassIdent; Complex m_refPrev; + double m_varPhase; + double m_varMag; MovingAverageUtilVar m_movingAverageIdent; static const int m_identBins = 10; Real m_identMins[m_identBins];