From 2f042fa0c442481db97fc656e79c782190457fc4 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:10:53 +0100 Subject: [PATCH 01/14] chore: fix gcc -wcatch-value --- src/chart/coherenceplot.cpp | 2 +- src/chart/meterplot.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chart/coherenceplot.cpp b/src/chart/coherenceplot.cpp index 7f7fe0bb..391f8ab6 100644 --- a/src/chart/coherenceplot.cpp +++ b/src/chart/coherenceplot.cpp @@ -175,7 +175,7 @@ void Chart::CoherenceThresholdLine::paint(QPainter *painter) painter->setRenderHints(QPainter::Antialiasing, true); painter->setPen(linePen); painter->drawLine(p1, p2); - } catch (std::invalid_argument) {} + } catch (std::invalid_argument&) {} } void CoherenceThresholdLine::parentWidthChanged() diff --git a/src/chart/meterplot.cpp b/src/chart/meterplot.cpp index c5a4e872..ead10438 100644 --- a/src/chart/meterplot.cpp +++ b/src/chart/meterplot.cpp @@ -356,7 +356,7 @@ QString MeterPlot::typeName() const noexcept { try { return m_typesMap.at(m_type); - } catch (std::out_of_range) {} + } catch (std::out_of_range&) {} return ""; } From 9c3e537efd77caa7cd8a8899cfec819ff051ddd7 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:15:28 +0100 Subject: [PATCH 02/14] chore: fix -Wunused-result; simplify map value lookup --- src/chart/meterplot.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/chart/meterplot.cpp b/src/chart/meterplot.cpp index ead10438..0ed2d661 100644 --- a/src/chart/meterplot.cpp +++ b/src/chart/meterplot.cpp @@ -380,14 +380,12 @@ void MeterPlot::setType(const Type &type) void MeterPlot::setType(const QString &type) { - std::find_if(m_typesMap.cbegin(), m_typesMap.cend(), - [&type, this](auto & e) { - if (e.second == type) { - setType(e.first); - return true; + for (auto& [enumType, strType] : m_typesMap) { + if (strType == type) { + setType(enumType); + return; } - return false; - }); + } } } // namespace chart From ffed518d08dbf25230f4ca37c20508c78413dfb6 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:19:48 +0100 Subject: [PATCH 03/14] chore: fix -Wreturn-type --- src/filtersource.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/filtersource.cpp b/src/filtersource.cpp index 9888ac7f..a914c4d8 100644 --- a/src/filtersource.cpp +++ b/src/filtersource.cpp @@ -211,6 +211,7 @@ complex FilterSource::calculate(float frequency) const case Peak: return calculatePeak(s); } + return 1; // is this the sensible default? } complex FilterSource::Bessel(bool hpf, complex s) const From dcd1578091d9e8ad96ad137fe715d71c7068d654 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:22:19 +0100 Subject: [PATCH 04/14] chore: fix -Wnarrowing --- src/generator/sinburst.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/generator/sinburst.cpp b/src/generator/sinburst.cpp index 0bdb2592..91b37b9e 100644 --- a/src/generator/sinburst.cpp +++ b/src/generator/sinburst.cpp @@ -16,9 +16,10 @@ * along with this program. If not, see . */ -#include #include "sinburst.h" +#include + SinBurst::SinBurst(QObject *parent) : OutputDevice{parent}, m_frequency(1000.f), @@ -48,8 +49,8 @@ Sample SinBurst::sample() } } - const static float PI10 = M_PI / 10; - Sample output = { m_burst ? m_gain *static_cast(sin(m_phase)) *sin(m_periods * PI10) / 2 : 0.f }; + constexpr static float PI10 = M_PI / 10.0; + Sample output = { m_burst ? m_gain * static_cast(std::sin(m_phase)) * std::sin(m_periods * PI10) / 2.f : 0.f }; return output; } From 86546db4c9de955fd01c8203989ce49be6f35455 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:23:07 +0100 Subject: [PATCH 05/14] chore: fix -Wunused-parameter --- src/remote/generatorremote.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/remote/generatorremote.cpp b/src/remote/generatorremote.cpp index 823bf4d1..459a991f 100644 --- a/src/remote/generatorremote.cpp +++ b/src/remote/generatorremote.cpp @@ -240,7 +240,7 @@ void GeneratorRemote::connectProperties() } } -void GeneratorRemote::dataError(const uint hash, const bool deactivate) +void GeneratorRemote::dataError(const uint hash, const bool) { if (hash != qHash(serverId())) { return; From cb1981baf0e91e180332f47bed6136ade5beb21b Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:23:56 +0100 Subject: [PATCH 06/14] chore: fix type leading to misleading -Wparentheses --- src/remote/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/remote/item.cpp b/src/remote/item.cpp index 81ea4ab1..cfb42c59 100644 --- a/src/remote/item.cpp +++ b/src/remote/item.cpp @@ -232,7 +232,7 @@ void Item::properiesChanged() property("active"); - if (!m_eventSilence && signalName != "stateChanged" & signalName != "activeChanged" ) { + if (!m_eventSilence && signalName != "stateChanged" && signalName != "activeChanged" ) { emit localChanged(propertyName); } } From 719e90dc0015666aa4360f41b04bf6e5fae7ae28 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:32:49 +0100 Subject: [PATCH 07/14] chore: silence -Wswitch on Windowing::m_usedMode --- src/source/sourcewindowing.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/source/sourcewindowing.cpp b/src/source/sourcewindowing.cpp index 6111e10f..a2cde643 100644 --- a/src/source/sourcewindowing.cpp +++ b/src/source/sourcewindowing.cpp @@ -190,6 +190,8 @@ void Windowing::resizeData() case Mode::LTW3: m_dataFT.setLogWindowDenominator(25); break; + default: + qDebug() << "unhandled usedMode" << m_usedMode; // Namely the different FFT modes, can they be handled? } m_dataFT.prepare(); From 82a82c5bfc4dbaffc61bdabd06cf87e65d26aad0 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:37:08 +0100 Subject: [PATCH 08/14] chore: fix -Wsign-compare --- src/source/sourcewindowing.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/source/sourcewindowing.cpp b/src/source/sourcewindowing.cpp index a2cde643..8cfebc75 100644 --- a/src/source/sourcewindowing.cpp +++ b/src/source/sourcewindowing.cpp @@ -360,7 +360,8 @@ void Windowing::updateFromTimeDomain(const Source::Shared &source) auto windowKoefficient = m_window.gain() / m_window.norm(); int j = 0; - for (int i = from/*, j = 0*/, f = m_deconvolutionSize / 2 + 1; i < end; ++i, ++j, time += dt, ++f) { + unsigned int f = m_deconvolutionSize / 2 + 1; + for (int i = from/*, j = 0*/; i < end; ++i, ++j, time += dt, ++f) { float value = (i >= 0 ? source->impulseValue(i) * m_window.get(j) * windowKoefficient : 0); From 35015d3d6da1b36ae2a7584b9038e969c2f5f76f Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:39:32 +0100 Subject: [PATCH 09/14] chore: fix -Wreorder; use `unsigned int` explicitly --- src/targettrace.cpp | 2 +- src/targettrace.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/targettrace.cpp b/src/targettrace.cpp index 0d2afb64..b2b4325b 100644 --- a/src/targettrace.cpp +++ b/src/targettrace.cpp @@ -45,7 +45,7 @@ const QList>> TargetTrace::m_presets = { }; TargetTrace::TargetTrace(Settings *settings, QObject *parent) : QObject(parent), - m_points{ m_presets[0].second }, m_settings(settings), m_preset(0) + m_points{ m_presets[0].second }, m_preset(0), m_settings(settings) { Q_ASSERT(!m_instance); diff --git a/src/targettrace.h b/src/targettrace.h index 2d85b462..e2021eec 100644 --- a/src/targettrace.h +++ b/src/targettrace.h @@ -93,7 +93,7 @@ class TargetTrace : public QObject QColor m_color = "#8BC34A"; std::vector m_points; - unsigned m_preset; + unsigned int m_preset; Settings *m_settings = nullptr; static TargetTrace *m_instance; From c21d5ba017fb0f0d91be8e354be0560ea198b043 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:44:19 +0100 Subject: [PATCH 10/14] chore: fix -Wsign-compare --- src/targettrace.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/targettrace.cpp b/src/targettrace.cpp index b2b4325b..23998396 100644 --- a/src/targettrace.cpp +++ b/src/targettrace.cpp @@ -199,9 +199,9 @@ void TargetTrace::setPreset(unsigned newPreset) std::lock_guard guard(m_mutex); - if (m_presets.size() > newPreset) { + if (static_cast(m_presets.size()) > newPreset) { m_preset = newPreset; - for (auto i = 0; i < m_points.size(); ++i) { + for (std::size_t i = 0; i < static_cast(m_points.size()); ++i) { m_points[i].setX(m_presets[m_preset].second[i].x()); m_points[i].setY(m_presets[m_preset].second[i].y()); } From 8485c60ecfde4aee5858e6bb2dabd721221818bd Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:51:19 +0100 Subject: [PATCH 11/14] chore: -Wtype-limits --- src/chart/rtaplot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chart/rtaplot.cpp b/src/chart/rtaplot.cpp index bfab5e17..ac73410c 100644 --- a/src/chart/rtaplot.cpp +++ b/src/chart/rtaplot.cpp @@ -130,7 +130,7 @@ void RTAPlot::setShowPeaks(bool showPeaks) bool RTAPlot::isPointsPerOctaveValid(unsigned int &value) const { - return value >= 0 && value <= 48; + return value <= 48; // >= 0 omitted since value is unsigned } RTAPlot::Scale RTAPlot::scale() const From 0ca8f1cdb6df44f9547c64a90573f7362de50f48 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:51:55 +0100 Subject: [PATCH 12/14] chore: -Wcatch-value --- src/chart/magnitudeplot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chart/magnitudeplot.cpp b/src/chart/magnitudeplot.cpp index 871c6d1e..021decdc 100644 --- a/src/chart/magnitudeplot.cpp +++ b/src/chart/magnitudeplot.cpp @@ -183,5 +183,5 @@ void MagnitudePlot::TargetTraceItem::paint(QPainter *painter) noexcept } path.lineTo(convert(points[0] + offset)); painter->drawPath(path); - } catch (std::invalid_argument) {} + } catch (std::invalid_argument&) {} } From fd4252808393730ea078b75a715c60c767f9adae Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:53:44 +0100 Subject: [PATCH 13/14] chore: -Wreturn-type --- src/math/windowfunction.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/math/windowfunction.cpp b/src/math/windowfunction.cpp index 78dcd7a5..1d581835 100644 --- a/src/math/windowfunction.cpp +++ b/src/math/windowfunction.cpp @@ -91,6 +91,8 @@ float WindowFunction::pointGain(float i, unsigned int N) const return std::pow(M_E, power); } } + // no windowing + return 1.0; } WindowFunction::Type WindowFunction::type() const From 021c3080c5b41c4b78055e52b49a807a3ca59052 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:56:09 +0100 Subject: [PATCH 14/14] fix: alsa card name being memory leaked --- src/audio/plugins/alsa.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/audio/plugins/alsa.cpp b/src/audio/plugins/alsa.cpp index 9d3bc8b3..29273945 100644 --- a/src/audio/plugins/alsa.cpp +++ b/src/audio/plugins/alsa.cpp @@ -17,6 +17,8 @@ */ #include "alsa.h" #include +#include + #include #define ALSA_BUFFER_SIZE 1024 #define ALSA_PERIOD_SIZE 64 @@ -43,6 +45,10 @@ struct pcm_guard { snd_pcm_t *handle = nullptr; }; +auto ptr_free = [](auto* ptr) { + return std::free(ptr); +}; + namespace audio { bool checkStatus(int errorCode, QString message = "", std::list goodStatuses = {0}); @@ -72,14 +78,22 @@ DeviceInfo::List AlsaPlugin::getDeviceInfoList() const { DeviceInfo::List list = {}; int cardIndex = -1, deviceIndex = -1; - char *cardName = nullptr; + // inner ptr allocated via malloc (via strdup), so it needs free() instead of delete + std::unique_ptr cardName = {nullptr, ptr_free}; snd_pcm_t *pcm = nullptr; snd_ctl_t *ctl = nullptr; while (checkStatus(snd_card_next(&cardIndex), "snd_ctl_open") && (cardIndex > -1 )) { char cardId[127]; snprintf(cardId, sizeof(cardId), "hw:%d", cardIndex); - checkContinue(snd_card_get_name(cardIndex, &cardName)); + { + // TODO replace with C++23 std::out_ptr(card_name) instead of tmp_cardName + char* tmp_cardName = nullptr; + bool cont = snd_card_get_name(cardIndex, &tmp_cardName); + cardName.reset(tmp_cardName); + checkContinue(cont); + + } checkContinue(snd_ctl_open(&ctl, cardId, 0)); deviceIndex = -1; @@ -89,7 +103,7 @@ DeviceInfo::List AlsaPlugin::getDeviceInfoList() const snprintf(plugId, sizeof(plugId), "plughw:%d,%d", cardIndex, deviceIndex); DeviceInfo deviceInfo(plugId, name()); - QString deviceName(cardName); + QString deviceName(cardName.get()); deviceName += " #" + QString::number(deviceIndex); deviceInfo.setName(deviceName);