From de0c3eb46adc78a901f6fcfbba727e41b7f51098 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 17 Oct 2016 05:55:03 +0200 Subject: [PATCH] fix(parser): Support default button index for actions Defining an action without a button index caused a segfault since the parser was treating it as the close of a previously opened action block. This makes the parser use button LEFT as a fallback. Also ensure that an action block has been opened before attempting to close the block. Fixes jaagr/lemonbuddy#104 --- include/components/parser.hpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/include/components/parser.hpp b/include/components/parser.hpp index edd9dcc3..ced711b8 100644 --- a/include/components/parser.hpp +++ b/include/components/parser.hpp @@ -3,7 +3,6 @@ #include #include "common.hpp" -#include "components/logger.hpp" #include "components/types.hpp" #include "components/signals.hpp" #include "utils/math.hpp" @@ -130,13 +129,19 @@ class parser { break; case 'A': - if (isdigit(data[0])) { + if (isdigit(data[0]) || data[0] == ':') { value = parse_action_cmd(data); + mousebtn btn = parse_action_btn(data); + m_actions.push_back(static_cast(btn)); + if (!g_signals::parser::action_block_open.empty()) - g_signals::parser::action_block_open.emit(parse_action_btn(data), value); - m_actions.push_back(data[0] - '0'); - value += "0::"; // make sure we strip the correct length (btn+wrapping colons) - } else { + g_signals::parser::action_block_open.emit(btn, value); + + // make sure we strip the correct length (btn+wrapping colons) + if (data[0] != ':') + value += "0"; + value += "::"; + } else if (!m_actions.empty()) { if (!g_signals::parser::action_block_close.empty()) g_signals::parser::action_block_close.emit(parse_action_btn(data)); m_actions.pop_back(); @@ -221,7 +226,9 @@ class parser { } // }}} mousebtn parse_action_btn(string data) { // {{{ - if (isdigit(data[0])) + if (data[0] == ':') + return mousebtn::LEFT; + else if (isdigit(data[0])) return static_cast(data[0] - '0'); else if (!m_actions.empty()) return static_cast(m_actions.back());