Skip to content

Commit a11ed06

Browse files
authored
Fixes #691 Prevent out of bounds access when ploting Throttle vs Frequency (#693)
Prevent out of bounds access when ploting Throttle vs Frequency
1 parent bfd5ab7 commit a11ed06

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

js/graph_spectrum_calc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ GraphSpectrumCalc._dataLoadFrequencyVsX = function(vsFieldNames, minValue = Infi
116116
}
117117
// Translate the average vs value to a bin index
118118
const avgVsValue = sumVsValues / fftChunkLength;
119-
const vsBinIndex = Math.floor(NUM_VS_BINS * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
119+
let vsBinIndex = Math.floor(NUM_VS_BINS * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
120+
// ensure that avgVsValue == flightSamples.maxValue does not result in an out of bounds access
121+
if (vsBinIndex === NUM_VS_BINS) { vsBinIndex = NUM_VS_BINS - 1; }
120122
numberSamples[vsBinIndex]++;
121123

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

0 commit comments

Comments
 (0)