Browse Source

wdsp: Prevent potential out-of-bounds array access

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>
chirpmodem-v8.0.0
Robin Getz 4 months ago
parent
commit
665f5e77ad
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 2
      wdsp/emnr.cpp
  2. 2
      wdsp/snba.cpp

2
wdsp/emnr.cpp

@ -233,7 +233,7 @@ void EMNR::NP::interpM ( @@ -233,7 +233,7 @@ void EMNR::NP::interpM (
double xlhigh;
double frac;
while ((x >= xvals[idx]) && (idx < nvals - 1))
while ((idx < nvals - 1) && (x >= xvals[idx]))
idx++;
xllow = log10 (xvals[idx - 1]);

2
wdsp/snba.cpp

@ -620,7 +620,7 @@ int SNBA::scanFrame( @@ -620,7 +620,7 @@ int SNBA::scanFrame(
if (nimp > 0)
{
while (merit[i] == merit[0] && i < nimp)
while (i < nimp && merit[i] == merit[0])
i++;
}

Loading…
Cancel
Save