Guard against nullptr access in LEDControl

If LEDControl is used without any LEDMode plugin, `cur_led_mode_` is
an unitialized pointer. This initializes it to `nullptr` and guards
against accessing it.

Signed-off-by: Johannes Becker <alfalfasprossen@gmail.com>
pull/858/head
Johannes Becker 5 years ago
parent d98dd72e17
commit 9ec48d0a4b

@ -28,7 +28,7 @@ static constexpr uint8_t uninitialized_mode_id = 255;
uint8_t LEDControl::mode_id = uninitialized_mode_id; uint8_t LEDControl::mode_id = uninitialized_mode_id;
uint8_t LEDControl::num_led_modes_ = LEDModeManager::numLEDModes(); uint8_t LEDControl::num_led_modes_ = LEDModeManager::numLEDModes();
LEDMode *LEDControl::cur_led_mode_; LEDMode *LEDControl::cur_led_mode_ = nullptr;
uint8_t LEDControl::syncDelay = 32; uint8_t LEDControl::syncDelay = 32;
uint16_t LEDControl::syncTimer = 0; uint16_t LEDControl::syncTimer = 0;
bool LEDControl::enabled_ = true; bool LEDControl::enabled_ = true;

@ -41,12 +41,14 @@ class LEDControl : public kaleidoscope::Plugin {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;
if (cur_led_mode_ != nullptr)
cur_led_mode_->update(); cur_led_mode_->update();
} }
static void refreshAt(KeyAddr key_addr) { static void refreshAt(KeyAddr key_addr) {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;
if (cur_led_mode_ != nullptr)
cur_led_mode_->refreshAt(key_addr); cur_led_mode_->refreshAt(key_addr);
} }
static void set_mode(uint8_t mode_id); static void set_mode(uint8_t mode_id);
@ -71,6 +73,7 @@ class LEDControl : public kaleidoscope::Plugin {
set_all_leds_to({0, 0, 0}); set_all_leds_to({0, 0, 0});
if (cur_led_mode_ != nullptr)
cur_led_mode_->onActivate(); cur_led_mode_->onActivate();
} }

Loading…
Cancel
Save