From cd09f8b24afad3a93486a781d19e4ce4861a3225 Mon Sep 17 00:00:00 2001 From: Marius Renner Date: Mon, 19 Sep 2022 00:28:53 +0200 Subject: [PATCH] Fix int8_t overflow in RGB heatmap effect The RGB heatmap effect currently has an issue where pressing the leftmost keys on the keyboard may light up the rightmost keys on the keyboard as well. This is because the distance calculation for the RGB heatmap effect uses int8_t to store the row distance and column distance. However, LED coordinates are stored as uint8_t, so it is possible to overflow the int8_t when calculating the row distance and column distance. Changing the row and column distance to int16_t fixes this overflow and resolves the original issue. --- quantum/rgb_matrix/animations/typing_heatmap_anim.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/rgb_matrix/animations/typing_heatmap_anim.h b/quantum/rgb_matrix/animations/typing_heatmap_anim.h index a05c07760ec4..00d137f1a6ce 100644 --- a/quantum/rgb_matrix/animations/typing_heatmap_anim.h +++ b/quantum/rgb_matrix/animations/typing_heatmap_anim.h @@ -29,7 +29,7 @@ void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { if (i_row == row && i_col == col) { g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32); } else { -# define LED_DISTANCE(led_a, led_b) sqrt16(((int8_t)(led_a.x - led_b.x) * (int8_t)(led_a.x - led_b.x)) + ((int8_t)(led_a.y - led_b.y) * (int8_t)(led_a.y - led_b.y))) +# define LED_DISTANCE(led_a, led_b) sqrt16(((int16_t)(led_a.x - led_b.x) * (int16_t)(led_a.x - led_b.x)) + ((int16_t)(led_a.y - led_b.y) * (int16_t)(led_a.y - led_b.y))) uint8_t distance = LED_DISTANCE(g_led_config.point[g_led_config.matrix_co[row][col]], g_led_config.point[g_led_config.matrix_co[i_row][i_col]]); # undef LED_DISTANCE if (distance <= RGB_MATRIX_TYPING_HEATMAP_SPREAD) {