From 84768d505ca5ca7726af89702662c0f271323915 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 8 Aug 2017 16:02:53 +0200 Subject: [PATCH] Layer_::updateKeyCache: Guard against out of bounds key coordinates It may happen that we get passed an UNKNOWN_KEYSWITCH_LOCATION, which will always be out of bounds. Lets not corrupt random memory when in this situation, but instead, return quickly. Signed-off-by: Gergely Nagy --- src/layers.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/layers.cpp b/src/layers.cpp index c05bde63..694e98c5 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -84,6 +84,9 @@ void Layer_::updateKeyCache(byte row, byte col) { int8_t layer = highestLayer; + if (row >= ROWS || col >= COLS) + return; + for (layer = highestLayer; layer >= DefaultLayer; layer--) { if (Layer.isOn(layer)) { Key mappedKey = (*getKey)(layer, row, col);