Avoid OOB in dynamic_keymap_reset (#17695)

This commit is contained in:
Joel Challis 2022-07-26 17:38:28 +01:00 committed by GitHub
parent 61da9286a1
commit c982d6c5e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -149,18 +149,25 @@ void dynamic_keymap_set_encoder(uint8_t layer, uint8_t encoder_id, bool clockwis
void dynamic_keymap_reset(void) { void dynamic_keymap_reset(void) {
// Reset the keymaps in EEPROM to what is in flash. // Reset the keymaps in EEPROM to what is in flash.
// All keyboards using dynamic keymaps should define a layout
// for the same number of layers as DYNAMIC_KEYMAP_LAYER_COUNT.
for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) { for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
for (int row = 0; row < MATRIX_ROWS; row++) { for (int row = 0; row < MATRIX_ROWS; row++) {
for (int column = 0; column < MATRIX_COLS; column++) { for (int column = 0; column < MATRIX_COLS; column++) {
if (layer < keymap_layer_count()) {
dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column])); dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
} else {
dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT);
}
} }
} }
#ifdef ENCODER_MAP_ENABLE #ifdef ENCODER_MAP_ENABLE
for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) { for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
if (layer < encodermap_layer_count()) {
dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0])); dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1])); dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
} else {
dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT);
dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT);
}
} }
#endif // ENCODER_MAP_ENABLE #endif // ENCODER_MAP_ENABLE
} }