diff options
author | Drashna Jaelre <drashna@live.com> | 2019-07-15 23:56:34 -0700 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2019-07-19 10:12:49 +0900 |
commit | 9fb4d678771532e1d85dcc85e11a7a77e77c6f2d (patch) | |
tree | e70b40cee4524e134aa2d9c94c94c39e0c7f2055 /quantum | |
parent | a20730f634a5791227ac1c3f0c0f371eaf350dd9 (diff) |
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')
-rw-r--r-- | quantum/process_keycode/process_leader.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index 897e9eabf6..ee8099ca21 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 |