Skip to content

Commit

Permalink
Fixes betaflight#691 Prevent out of bounds access when ploting Thrott…
Browse files Browse the repository at this point in the history
…le vs Frequency (betaflight#693)

Prevent out of bounds access when ploting Throttle vs Frequency
  • Loading branch information
tbolin authored Jan 23, 2024
1 parent bfd5ab7 commit a11ed06
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/graph_spectrum_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ GraphSpectrumCalc._dataLoadFrequencyVsX = function(vsFieldNames, minValue = Infi
}
// Translate the average vs value to a bin index
const avgVsValue = sumVsValues / fftChunkLength;
const vsBinIndex = Math.floor(NUM_VS_BINS * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
let vsBinIndex = Math.floor(NUM_VS_BINS * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
// ensure that avgVsValue == flightSamples.maxValue does not result in an out of bounds access
if (vsBinIndex === NUM_VS_BINS) { vsBinIndex = NUM_VS_BINS - 1; }
numberSamples[vsBinIndex]++;

// add the output from the fft to the row given by the vs value bin index
Expand Down

0 comments on commit a11ed06

Please sign in to comment.