aboutsummaryrefslogtreecommitdiffstats
path: root/quantum/process_keycode/process_leader.c
diff options
context:
space:
mode:
authorGravatar Drashna Jaelre <drashna@live.com>2019-07-15 23:56:34 -0700
committerGravatar skullydazed <skullydazed@users.noreply.github.com>2019-07-15 23:56:34 -0700
commit09f5767072b65d98371199ab03981940d132b123 (patch)
tree64ff932bff4e796447a65f2fb9a4241379257668 /quantum/process_keycode/process_leader.c
parented6a872911ba13383585002699a0024510d7b1f4 (diff)
downloadqmk_firmware-09f5767072b65d98371199ab03981940d132b123.tar.gz
Add out of bound check for Leader Key sequence array (#5840)
* Add out of bound check for Leader Key sequence array * A shot at advanced C stuff for Leader Key optimization * Revert most changes * Change default back * Include string.h if compiling for ARM * Use sizeof instead of a number
Diffstat (limited to 'quantum/process_keycode/process_leader.c')
-rw-r--r--quantum/process_keycode/process_leader.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c
index 897e9eabf..ee8099ca2 100644
--- a/quantum/process_keycode/process_leader.c
+++ b/quantum/process_keycode/process_leader.c
@@ -17,6 +17,9 @@
#ifdef LEADER_ENABLE
#include "process_leader.h"
+#ifdef __arm__
+# include <string.h>
+#endif
#ifndef LEADER_TIMEOUT
#define LEADER_TIMEOUT 300
@@ -41,11 +44,7 @@ void qk_leader_start(void) {
leading = true;
leader_time = timer_read();
leader_sequence_size = 0;
- leader_sequence[0] = 0;
- leader_sequence[1] = 0;
- leader_sequence[2] = 0;
- leader_sequence[3] = 0;
- leader_sequence[4] = 0;
+ memset(leader_sequence, 0, sizeof(leader_sequence));
}
bool process_leader(uint16_t keycode, keyrecord_t *record) {
@@ -58,8 +57,13 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) {
keycode = keycode & 0xFF;
}
#endif // LEADER_KEY_STRICT_KEY_PROCESSING
- leader_sequence[leader_sequence_size] = keycode;
- leader_sequence_size++;
+ if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) {
+ leader_sequence[leader_sequence_size] = keycode;
+ leader_sequence_size++;
+ } else {
+ leading = false;
+ leader_end();
+ }
#ifdef LEADER_PER_KEY_TIMING
leader_time = timer_read();
#endif