From 8aea40f3005ee5555662e6bddbc40f6a2d720187 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Mon, 10 Aug 2026 20:21:35 -0400 Subject: [PATCH] channel: fix bandwidth index validation Use the validated bandwidth index when accessing bandwidth tables in the ChirpChat, MeshCore, and Meshtastic channel GUIs. The previous code used the raw UI value after clamping it into m_bandwidthIndex, allowing negative or out-of-range array accesses. Found by cppcheck. Signed-off-by: Robin Getz --- plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp | 2 +- plugins/channeltx/modchirpchat/chirpchatmodgui.cpp | 2 +- plugins/channeltx/modmeshcore/meshcoremodgui.cpp | 2 +- plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp b/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp index 0d4ce30a6..5ffa4dbd0 100644 --- a/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp +++ b/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp @@ -188,7 +188,7 @@ void ChirpChatDemodGUI::on_BW_valueChanged(int value) m_settings.m_bandwidthIndex = ChirpChatDemodSettings::nbBandwidths - 1; } - int thisBW = ChirpChatDemodSettings::bandwidths[value]; + int thisBW = ChirpChatDemodSettings::bandwidths[m_settings.m_bandwidthIndex]; ui->BWText->setText(QString("%1 Hz").arg(thisBW)); m_channelMarker.setBandwidth(thisBW); ui->glSpectrum->setSampleRate(thisBW); diff --git a/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp b/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp index 07e2f0e07..271091d5c 100644 --- a/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp +++ b/plugins/channeltx/modchirpchat/chirpchatmodgui.cpp @@ -163,7 +163,7 @@ void ChirpChatModGUI::on_bw_valueChanged(int value) m_settings.m_bandwidthIndex = ChirpChatModSettings::nbBandwidths - 1; } - int thisBW = ChirpChatModSettings::bandwidths[value]; + int thisBW = ChirpChatModSettings::bandwidths[m_settings.m_bandwidthIndex]; ui->bwText->setText(QString("%1 Hz").arg(thisBW)); m_channelMarker.setBandwidth(thisBW); diff --git a/plugins/channeltx/modmeshcore/meshcoremodgui.cpp b/plugins/channeltx/modmeshcore/meshcoremodgui.cpp index 0b3adbd34..75d9b8d3b 100644 --- a/plugins/channeltx/modmeshcore/meshcoremodgui.cpp +++ b/plugins/channeltx/modmeshcore/meshcoremodgui.cpp @@ -462,7 +462,7 @@ void MeshcoreModGUI::on_bw_valueChanged(int value) m_settings.m_bandwidthIndex = MeshcoreModSettings::nbBandwidths - 1; } - int thisBW = MeshcoreModSettings::bandwidths[value]; + int thisBW = MeshcoreModSettings::bandwidths[m_settings.m_bandwidthIndex]; ui->bwText->setText(QString("%1 Hz").arg(thisBW)); m_channelMarker.setBandwidth(thisBW); diff --git a/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp b/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp index c7cbdecbe..055ac2f7b 100644 --- a/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp +++ b/plugins/channeltx/modmeshtastic/meshtasticmodgui.cpp @@ -451,7 +451,7 @@ void MeshtasticModGUI::on_bw_valueChanged(int value) m_settings.m_bandwidthIndex = MeshtasticModSettings::nbBandwidths - 1; } - int thisBW = MeshtasticModSettings::bandwidths[value]; + int thisBW = MeshtasticModSettings::bandwidths[m_settings.m_bandwidthIndex]; ui->bwText->setText(QString("%1 Hz").arg(thisBW)); m_channelMarker.setBandwidth(thisBW);