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
pull/6213/merge 0.6.426
Drashna Jaelre 5 years ago committed by skullydazed
parent ed6a872911
commit 09f5767072

@ -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

Loading…
Cancel
Save