From 485e45ea67cff8b823e7dbadba47da75fc3bfc31 Mon Sep 17 00:00:00 2001 From: lokher Date: Thu, 25 Aug 2022 15:28:25 +0800 Subject: Fix host_led_pin_list out of bound issue --- keyboards/keychron/bluetooth/indicator.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'keyboards/keychron/bluetooth/indicator.c') diff --git a/keyboards/keychron/bluetooth/indicator.c b/keyboards/keychron/bluetooth/indicator.c index bfe0f5cb17..38e35cceeb 100644 --- a/keyboards/keychron/bluetooth/indicator.c +++ b/keyboards/keychron/bluetooth/indicator.c @@ -237,10 +237,16 @@ static void indicator_timer_cb(void *arg) { } #ifdef HOST_LED_PIN_LIST - if (indicator_config.value && (indicator_config.value & 0x80)) { - writePin(host_led_pin_list[indicator_config.value & 0x0F], HOST_LED_PIN_ON_STATE); - } else { - writePin(host_led_pin_list[indicator_config.value & 0x0F], !HOST_LED_PIN_ON_STATE); + if (indicator_config.value) + { + uint8_t idx = (indicator_config.value & 0x0F) - 1; + chDbgAssert(idx < HOST_DEVICES_COUNT, "array out of bounds"); + + if (indicator_config.value & 0x80) { + writePin(host_led_pin_list[idx], HOST_LED_PIN_ON_STATE); + } else { + writePin(host_led_pin_list[idx], !HOST_LED_PIN_ON_STATE); + } } #endif -- cgit v1.2.3