From 09f5767072b65d98371199ab03981940d132b123 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 15 Jul 2019 23:56:34 -0700 Subject: 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 --- quantum/process_keycode/process_leader.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'quantum/process_keycode/process_leader.c') 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 +#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 -- cgit v1.2.3 From e5d2cb8f98fb4dbec3c64e19acfaa4e6db57e257 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 16 Jul 2019 09:22:29 -0700 Subject: Fix Preprocessor check for Leader Keys --- quantum/process_keycode/process_leader.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'quantum/process_keycode/process_leader.c') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index ee8099ca21..f787e6b017 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -17,9 +17,7 @@ #ifdef LEADER_ENABLE #include "process_leader.h" -#ifdef __arm__ -# include -#endif +#include #ifndef LEADER_TIMEOUT #define LEADER_TIMEOUT 300 -- cgit v1.2.3 From b624f32f944acdc59dcb130674c09090c5c404cb Mon Sep 17 00:00:00 2001 From: skullY Date: Fri, 30 Aug 2019 11:19:03 -0700 Subject: clang-format changes --- quantum/process_keycode/process_leader.c | 86 ++++++++++++++++---------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'quantum/process_keycode/process_leader.c') diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index f787e6b017..58a615d85a 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -16,64 +16,64 @@ #ifdef LEADER_ENABLE -#include "process_leader.h" -#include +# include "process_leader.h" +# include -#ifndef LEADER_TIMEOUT - #define LEADER_TIMEOUT 300 -#endif +# ifndef LEADER_TIMEOUT +# define LEADER_TIMEOUT 300 +# endif -__attribute__ ((weak)) -void leader_start(void) {} +__attribute__((weak)) void leader_start(void) {} -__attribute__ ((weak)) -void leader_end(void) {} +__attribute__((weak)) void leader_end(void) {} // Leader key stuff -bool leading = false; +bool leading = false; uint16_t leader_time = 0; -uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; -uint8_t leader_sequence_size = 0; +uint16_t leader_sequence[5] = {0, 0, 0, 0, 0}; +uint8_t leader_sequence_size = 0; void qk_leader_start(void) { - if (leading) { return; } - leader_start(); - leading = true; - leader_time = timer_read(); - leader_sequence_size = 0; - memset(leader_sequence, 0, sizeof(leader_sequence)); + if (leading) { + return; + } + leader_start(); + leading = true; + leader_time = timer_read(); + leader_sequence_size = 0; + memset(leader_sequence, 0, sizeof(leader_sequence)); } bool process_leader(uint16_t keycode, keyrecord_t *record) { - // Leader key set-up - if (record->event.pressed) { - if (leading) { - if (timer_elapsed(leader_time) < LEADER_TIMEOUT) { -#ifndef LEADER_KEY_STRICT_KEY_PROCESSING - if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { - keycode = keycode & 0xFF; - } -#endif // LEADER_KEY_STRICT_KEY_PROCESSING - if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) { - leader_sequence[leader_sequence_size] = keycode; - leader_sequence_size++; + // Leader key set-up + if (record->event.pressed) { + if (leading) { + if (timer_elapsed(leader_time) < LEADER_TIMEOUT) { +# ifndef LEADER_KEY_STRICT_KEY_PROCESSING + if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { + keycode = keycode & 0xFF; + } +# endif // LEADER_KEY_STRICT_KEY_PROCESSING + 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 + return false; + } } else { - leading = false; - leader_end(); + if (keycode == KC_LEAD) { + qk_leader_start(); + } } -#ifdef LEADER_PER_KEY_TIMING - leader_time = timer_read(); -#endif - return false; - } - } else { - if (keycode == KC_LEAD) { - qk_leader_start(); - } } - } - return true; + return true; } #endif -- cgit v1.2.3