Fix cppcheck warnings where array elements were accessed before validating
their indices. Reorder conditional expressions to ensure bounds checks are
performed before array accesses, taking advantage of C++ short-circuit
evaluation.
In EMNR::NP::interpM(), check the index limit before accessing xvals[idx].
In SNBA::scanFrame(), verify i is within the merit array bounds before
evaluating merit[i].
These changes improve defensive programming practices and prevent potential
undefined behavior if an index exceeds the valid range. No functional changes.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
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 <rgetz503@gmail.com>
Replace the runtime-sized temporary array in the int8_t specialization of
MinSumAlgorithm::finalp() with std::vector.
The array size is determined by the runtime value of cnt, requiring a
compiler VLA extension. Using std::vector preserves the existing behavior
while removing the dependency on non-standard language extensions.
This eliminates remaining -Wvla warnings (for me) reported from
ldpctool/algorithms.h
Part of #2830
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Replace the runtime-sized temporary array in
MinSumCAlgorithm::finalp() with std::vector.
The temporary array size depends on the runtime value of cnt, requiring a
compiler VLA extension. Using std::vector preserves the existing behavior
while removing the dependency on non-standard language extensions.
This eliminates ~6 of remaining -Wvla warnings (for me) reported
from ldpctool/algorithms.h
Part of #2830
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Replace the runtime-sized temporary array in the int8_t specialization of
OffsetMinSumAlgorithm::finalp() with std::vector.
The array size is determined by the runtime value of cnt, requiring a
compiler VLA extension. Using std::vector preserves the existing behavior
while removing the dependency on non-standard language extensions.
This eliminates ~12 of remaining -Wvla warnings (for me) reported
from ldpctool/algorithms.h
Part of #2830
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Replace the runtime-sized temporary arrays in
OffsetMinSumAlgorithm::finalp() with std::vector.
The array sizes depend on the runtime value of cnt, requiring compiler
support for variable length arrays. Using std::vector removes this
non-standard extension while preserving the existing algorithm and memory
layout.
This eliminates ~24 of remaining -Wvla warnings (for me) reported
from ldpctool/algorithms.h.
Part of #2830
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Replace the runtime-sized temporary arrays used by
MinSumAlgorithm<SIMD<...>>::finalp() with std::vector.
The array sizes are determined at runtime from the number of links,
making them variable-length arrays that rely on compiler extensions.
Using std::vector removes the dependency on VLA support while
preserving the existing algorithm and behavior.
This eliminates ~24 of remaining -Wvla warnings (for me) reported
from ldpctool/algorithms.h.
Part of #2830
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Replace the runtime-sized stack array in the spectrum processing path
with std::vector to avoid compiler VLA extensions.
Although the spectrum template is not instantiated as part of the
current SDRangel build, GCC still emits -Wvla warnings while parsing
the template definition. This change removes those warnings and keeps
the template valid for future use.
Use std::copy() and vector::data() when accessing the underlying
storage.
Part of #2830
Signed-off-by: Robin Getz <rgetz503@gmail.com>
The spectrum template was not being instantiated by the current build,
so stale accesses to cfft_engine::n went unnoticed.
Replace direct accesses to the private cfft_engine member with the
public size() accessor. This restores spectrum compilation and allows
the upcoming VLA cleanup to be built and tested.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Clear the m_open flag when closing PlutoSDR input and output
devices. Previously closeDevice() released m_deviceParams but left
m_open set, leaving the object in an inconsistent state where code
could treat a closed device as still valid.
This was exposed when reloading a running PlutoSDR device, where GUI
updates could access the partially torn-down device state.
Hopefully fixes#2833 (I don't have a windows machine to test).
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Correct std::fill() calls in SPHP::flush() that used x0.end() as the
end iterator when clearing x1, y0, and y1.
The incorrect ranges were likely introduced by a copy/paste error and
resulted in iterator pairs from different containers being used
together, causing undefined behavior.
Use each buffer's own end iterator when clearing its contents.
Detected by cppcheck's mismatchingContainer check.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Only apply channel settings after BasicChannelSettingsDialog returns an
accepted result. Previously, the return value from dialog.exec() was ignored
and settings were copied from the dialog regardless of whether the dialog was
accepted or rejected.
This could cause changes made in the channel settings dialog to be applied
even when the user discarded them. Check the dialog result before updating
the channel title, color, Reverse API configuration, and stream index to keep
the GUI state synchronized with the user's action.
This also fixes the Coverity CHECKED_RETURN warning for the unchecked
QDialog::exec() return value.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize previously unset FFTMeasurement members with defined default
values so newly constructed measurement objects start in a known state.
Although these fields are populated during normal measurement processing,
constructors should establish a complete and deterministic object state
rather than leaving scalar members with indeterminate values. This also
makes the class safer if the initialization sequence changes in the future.
This fixes a Coverity UNINIT_CTOR warning caused by uninitialized scalar
members in the constructor.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_min and m_max in the SensorMeasurements constructor to ensure
the object has a valid state immediately after construction, before init()
is called.
Although init() sets these values before normal use, constructors should
fully initialize all class members to avoid leaving objects with undefined
state and to make the class safe to use regardless of initialization order.
This fixes a Coverity UNINIT_CTOR warning caused by uninitialized scalar
members in the constructor.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
RadioAstronomyGUI::spectrumSeries_clicked() called
calcVrAndDistanceToPeak() without verifying that currentFFT() returned a
valid FFTMeasurement. Since currentFFT() can return nullptr and
calcVrAndDistanceToPeak() immediately dereferences the pointer, this could
result in a null pointer dereference.
Guard the calls so they are only made when a valid FFT measurement is
available, matching the existing pattern used elsewhere in the class.
Reported by Coverity (CID 649213).
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Replace the temporary CRC working buffer in `LDPC::ft8_crc()` with a
`std::vector<int>`.
The vector is value-initialized, preserving the existing zero-padding
behavior, while `std::memcpy()` copies the input message into the front
of the buffer. This removes the manual `malloc()`/`free()` pair, simplifies
the implementation, and uses RAII for temporary storage.
This change also addresses a cppcheck warning about a possible null pointer
dereference following malloc() failure. If memory allocation now fails,
std::vector will throw std::bad_alloc rather than returning a null pointer
that would be dereferenced. The algorithm and behavior are otherwise
unchanged.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Built-in devices were previously always selectable regardless of
their claimed state. The "show devices in use" change
https://github.com/f4exb/sdrangel/commit/964bc0994d1e5c54ef8b08eb9102e0ee4f7d744e
inadvertently disabled all claimed devices in the selection dialog,
preventing multiple instances of FileInput, RemoteTCPInput, AudioInput,
TestSource and other built-in sources from being opened. :(
Only claimed physical devices are now disabled and marked
"[in use]". Built-in devices remain selectable as before.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
The MeshCore mod plugin references SWGMeshcoreModActions in
meshcoremod.cpp, but MeshcoreMod.yaml had no MeshcoreModActions
section. When swagger files are regenerated, the auto-generated
SWGChannelActions.h/cpp lose the meshcore_mod_actions member and
accessors, which would break compilation of meshcoremod.cpp.
Changes across five files:
- MeshcoreMod.yaml: add MeshcoreModActions definition (sendNow
field, matching existing hand-authored SWGMeshcoreModActions)
- ChannelActions.yaml: add MeshcoreModActions pointing to
the new section
- SWGModelFactory.h: add #include and create() registration
block for SWGMeshcoreModActions (was missing despite
SWGMeshcoreModSettings/MeshcoreDemod* being registered)
- webapirequestmapper.cpp: add channelActionsKey routing branch
for MeshcoreModActions (was completely absent)
- webapiutils.cpp: add m_channelURIToSettingsKey and
m_channelTypeToSettingsKey entries for both MeshcoreDemod and
MeshcoreMod (were missing, unlike ChirpChat and Meshtastic
which have entries for their channel types)
The ui object is created during MeshcoreDemodGUI and MeshtasticDemodGUI
construction and remains valid for the lifetime of the widget. Remove
the unnecessary null check to avoid misleading static analysis tools
into assuming ui can be null.
This resolves a Coverity false positive where the later call to
updateDechirpModeUI() was reported as a possible null dereference
in both places.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Fix Coverity CID 649243 (DIVIDE_BY_ZERO) by validating sweep step
values before calculating 2D sweep dimensions.
Move sweep step validation to on_startStop_clicked() so invalid sweep
configurations are reported to the user before a sweep begins. Display
an error message when either sweep step is zero and prevent the sweep
from starting.
Retain defensive validation when updating 2D sweep settings to guard
against invalid configurations received from saved settings or other
code paths.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize the coordinate and bearing variables used by
VORModel::findIntersection() and declare the validity flags as bool.
Coverity reported that lat1, lon1, bearing1, lat2, lon2, and bearing2
could be passed uninitialized to calcIntersectionPoint(). While the
current control flow is intended to assign these values before the
corresponding validity flag is set, they were not initialized at
declaration, leaving undefined behavior if that invariant were ever
broken.
Initializing the variables removes the possibility of using
indeterminate values, satisfies static analysis, and makes the code
more robust against future modifications. The validity flags are also
changed from float to bool to match their intended use.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Fix a Coverity UNINIT warning in RadioAstronomyGUI::update2DImage()
where the intensity variable could be used uninitialized if
m_powerYUnits contained an unexpected value and followed the default path.
Handle the default switch case by logging a warning and falling back
to fft->m_totalPowerdBFS, ensuring intensity is always initialized
before being used while providing diagnostics for invalid enum values.
Fixes Coverity CID 649242.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Fix Coverity CID 649221 (DIVIDE_BY_ZERO) by validating the cold
calibration power sum before calculating the Y-factor.
Refactor calcCalTrx() to use early returns for invalid calibration
states and avoid duplicated UI clearing logic. Also handle the
undefined Y-factor case when hot and cold measurements have equal power.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Fix Coverity CID 649238 (DIVIDE_BY_ZERO) by validating the reference
column count before using it as a divisor in plotChart().
The reference column count can be cleared when removing reference data,
in on_clearReference_clicked() so ensure chart rendering handles an empty
reference configuration safely.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Fix Coverity CID 649215 (OVERFLOW_BEFORE_WIDEN) by ensuring the band
preset frequency calculation is widened to 64-bit before converting
kHz to Hz.
This prevents a potential 32-bit intermediate overflow when applying
band presets (which is likely not a real issue, but it keeps the
analyzer happy).
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Fix Coverity CID 649088 (CONSTANT_EXPRESSION_RESULT) in the BDS 4,1
next waypoint decoding logic.
The high bit contribution to waypoint character c[5] was incorrectly
shifted right by 3, causing the expression to always evaluate to zero
and discard a valid bit from the decoded character. Change the shift
direction to correctly place the extracted bit into the character field.
This restores proper decoding of the BDS 4,1 waypoint string and removes
the Coverity warning.
Signed-off-by: Robin Getz <rgetz503@gmail.com>