From 480bfbd0217ce349d6c129ec35c058f8b9b6cdb4 Mon Sep 17 00:00:00 2001 From: "James N. V. Cash" Date: Fri, 27 Oct 2017 17:28:32 -0400 Subject: [PATCH 1/3] Guard against out-of-bounds layer --- src/Kaleidoscope/EEPROM-Keymap.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Kaleidoscope/EEPROM-Keymap.cpp b/src/Kaleidoscope/EEPROM-Keymap.cpp index 7d83e792..0d2b00c6 100644 --- a/src/Kaleidoscope/EEPROM-Keymap.cpp +++ b/src/Kaleidoscope/EEPROM-Keymap.cpp @@ -113,6 +113,9 @@ bool EEPROMKeymap::focusKeymapLayer(const char *command) { } uint8_t layer = Serial.parseInt(); + if (layer >= max_layers_) { + return false; + } uint16_t keysPerLayer = ROWS * COLS; uint16_t offset = layer * keysPerLayer; if (Serial.peek() == '\n') { From 0073be9a74b87d6772acb6b1e0c7268282951bd4 Mon Sep 17 00:00:00 2001 From: "James N. V. Cash" Date: Mon, 30 Oct 2017 08:16:37 -0400 Subject: [PATCH 2/3] Fix error in storing keys by layer --- src/Kaleidoscope/EEPROM-Keymap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kaleidoscope/EEPROM-Keymap.cpp b/src/Kaleidoscope/EEPROM-Keymap.cpp index 0d2b00c6..5a0a6636 100644 --- a/src/Kaleidoscope/EEPROM-Keymap.cpp +++ b/src/Kaleidoscope/EEPROM-Keymap.cpp @@ -117,7 +117,6 @@ bool EEPROMKeymap::focusKeymapLayer(const char *command) { return false; } uint16_t keysPerLayer = ROWS * COLS; - uint16_t offset = layer * keysPerLayer; if (Serial.peek() == '\n') { for (uint8_t row = 0; row < ROWS; row++) { for (uint8_t col = 0; col < COLS; col++) { @@ -127,8 +126,9 @@ bool EEPROMKeymap::focusKeymapLayer(const char *command) { } } } else { + uint16_t offset = layer * keysPerLayer; for (uint16_t k = 0; (k < keysPerLayer) && (Serial.peek() != '\n'); k++) { - updateKey(layer + k, parseKey()); + updateKey(offset + k, parseKey()); } } From c298d22827a6e90235c0bf0b507f3c6df99118be Mon Sep 17 00:00:00 2001 From: "James N. V. Cash" Date: Mon, 30 Oct 2017 10:42:46 -0400 Subject: [PATCH 3/3] Only need keysPerLayer in the updating branch of the conditional --- src/Kaleidoscope/EEPROM-Keymap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kaleidoscope/EEPROM-Keymap.cpp b/src/Kaleidoscope/EEPROM-Keymap.cpp index 5a0a6636..a8bd42bf 100644 --- a/src/Kaleidoscope/EEPROM-Keymap.cpp +++ b/src/Kaleidoscope/EEPROM-Keymap.cpp @@ -116,7 +116,6 @@ bool EEPROMKeymap::focusKeymapLayer(const char *command) { if (layer >= max_layers_) { return false; } - uint16_t keysPerLayer = ROWS * COLS; if (Serial.peek() == '\n') { for (uint8_t row = 0; row < ROWS; row++) { for (uint8_t col = 0; col < COLS; col++) { @@ -126,6 +125,7 @@ bool EEPROMKeymap::focusKeymapLayer(const char *command) { } } } else { + uint16_t keysPerLayer = ROWS * COLS; uint16_t offset = layer * keysPerLayer; for (uint16_t k = 0; (k < keysPerLayer) && (Serial.peek() != '\n'); k++) { updateKey(offset + k, parseKey());