Check the value of macroIndex
This commit is contained in:
@@ -52,13 +52,14 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
|
||||
return ParserError_InvalidKeymapCount;
|
||||
}
|
||||
for (uint8_t keymapIdx = 0; keymapIdx < keymapCount; keymapIdx++) {
|
||||
errorCode = ParseKeymap(buffer, keymapIdx, keymapCount);
|
||||
errorCode = ParseKeymap(buffer, keymapIdx, keymapCount, macroCount);
|
||||
if (errorCode != ParserError_Success) {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
if (!ParserRunDry) {
|
||||
AllKeymapsCount = keymapCount;
|
||||
AllMacrosCount = macroCount;
|
||||
}
|
||||
return ParserError_Success;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
ParserError_InvalidKeymapCount,
|
||||
ParserError_InvalidAbbreviationLen,
|
||||
ParserError_InvalidMacroCount,
|
||||
ParserError_InvalidSerializedPlayMacroAction,
|
||||
} parser_error_t;
|
||||
|
||||
// Functions:
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#include "keymaps.h"
|
||||
#include "led_display.h"
|
||||
|
||||
uint8_t tempKeymapCount;
|
||||
static uint8_t tempKeymapCount;
|
||||
static uint8_t tempMacroCount;
|
||||
|
||||
static parser_error_t parseNoneAction(key_action_t *keyAction, config_buffer_t *buffer)
|
||||
{
|
||||
@@ -71,6 +72,9 @@ static parser_error_t parsePlayMacroAction(key_action_t *keyAction, config_buffe
|
||||
{
|
||||
uint8_t macroIndex = readUInt8(buffer);
|
||||
|
||||
if (macroIndex >= tempMacroCount) {
|
||||
return ParserError_InvalidSerializedPlayMacroAction;
|
||||
}
|
||||
keyAction->type = KeyActionType_SwitchKeymap;
|
||||
keyAction->playMacro.macroId = macroIndex;
|
||||
return ParserError_Success;
|
||||
@@ -192,7 +196,7 @@ static parser_error_t parseLayer(config_buffer_t *buffer, uint8_t layer)
|
||||
return ParserError_Success;
|
||||
}
|
||||
|
||||
parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount)
|
||||
parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount, uint8_t macroCount)
|
||||
{
|
||||
uint16_t offset = buffer->offset;
|
||||
parser_error_t errorCode;
|
||||
@@ -222,6 +226,7 @@ parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t k
|
||||
}
|
||||
}
|
||||
tempKeymapCount = keymapCount;
|
||||
tempMacroCount = macroCount;
|
||||
for (uint8_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
|
||||
errorCode = parseLayer(buffer, layerIdx);
|
||||
if (errorCode != ParserError_Success) {
|
||||
|
||||
@@ -52,6 +52,6 @@
|
||||
|
||||
// Functions:
|
||||
|
||||
parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount);
|
||||
parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount, uint8_t macroCount);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "led_display.h"
|
||||
#include "config_parser/parse_keymap.h"
|
||||
#include "config_parser/config_globals.h"
|
||||
#include "macros.h"
|
||||
|
||||
// TODO: Restore Ctrl and Super keys and Mod+N.
|
||||
|
||||
@@ -16,7 +17,7 @@ void Keymaps_Switch(uint8_t index)
|
||||
{
|
||||
CurrentKeymapIndex = index;
|
||||
UserConfigBuffer.offset = AllKeymaps[index].offset;
|
||||
ParseKeymap(&UserConfigBuffer, index, AllKeymapsCount);
|
||||
ParseKeymap(&UserConfigBuffer, index, AllKeymapsCount, AllMacrosCount);
|
||||
LedDisplay_SetText(AllKeymaps[index].abbreviationLen, AllKeymaps[index].abbreviation);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "macros.h"
|
||||
|
||||
macro_reference_t AllMacros[MAX_MACRO_NUM];
|
||||
uint8_t AllMacrosCount;
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
// Variables:
|
||||
|
||||
extern macro_reference_t AllMacros[MAX_MACRO_NUM];
|
||||
extern uint8_t AllMacrosCount;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user