prevent array bounds violation

+ don't use dynamic array for heights[] - dynamic arrays are using malloc() -> heap frag.
This commit is contained in:
Frank
2024-07-15 13:24:18 +02:00
parent 6d1615189b
commit 4f6eb8b161

View File

@@ -8420,7 +8420,7 @@ uint16_t mode_GEQLASER(void) {
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[2];
uint8_t heights[NUM_BANDS] = { 0 };
uint8_t heights[NUM_GEQ_CHANNELS] = { 0 };
for (int i=0; i<NUM_BANDS; i++) {
heights[i] = map8(fftResult[i],0,rows*0.85);
@@ -8441,7 +8441,7 @@ uint16_t mode_GEQLASER(void) {
ledColorTemp = color_fade(ledColor,32,true);
for (int y = heights[i+1]; y <= heights[i]; y++) { // don't bother drawing what we'll hide anyway
for (int y = (i<NUM_BANDS-1) ? heights[i+1] : 0; y <= heights[i]; y++) { // don't bother drawing what we'll hide anyway
SEGMENT.drawLine(linex+(cols/NUM_BANDS)-1,rows-y-1,*projector,horizon,ledColorTemp,false,distance); // right side perspective
}
@@ -8470,7 +8470,7 @@ uint16_t mode_GEQLASER(void) {
ledColorTemp = color_fade(ledColor,32,true);
for (uint_fast8_t y = heights[i-1]; y <= heights[i]; y++) { // don't bother drawing what we'll hide anyway
for (uint_fast8_t y = (i>0) ? heights[i-1] : 0; y <= heights[i]; y++) { // don't bother drawing what we'll hide anyway
SEGMENT.drawLine(linex,rows-y-1,*projector,horizon,ledColorTemp,false,distance); // left side perspective
}