From f79018cffd82e369a8e634be6d7140b8fdd50b9c Mon Sep 17 00:00:00 2001 From: Leira Hua Date: Sat, 24 Dec 2016 17:42:31 -0800 Subject: [PATCH] Added string length check when checking switch params Fixes #1051 --- src/command_manager.cc | 2 +- src/parameters_parser.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index d5307032..fa970d74 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -421,7 +421,7 @@ void CommandManager::execute_single_command(CommandParameters params, if (params.empty()) return; - ConstArrayView param_view(params.begin()+1, params.end()); + ParameterList param_view(params.begin()+1, params.end()); auto command_it = find_command(context, params[0]); if (command_it == m_commands.end()) throw command_not_found(params[0]); diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc index 1633aa6b..697f1407 100644 --- a/src/parameters_parser.cc +++ b/src/parameters_parser.cc @@ -23,7 +23,7 @@ ParametersParser::ParametersParser(ParameterList params, { if (not only_pos and params[i] == "--") only_pos = true; - else if (not only_pos and params[i][0_byte] == '-') + else if (not only_pos and params[i].length() > 0 and params[i][0_byte] == '-') { auto it = m_desc.switches.find(params[i].substr(1_byte)); if (it == m_desc.switches.end()) @@ -36,7 +36,7 @@ ParametersParser::ParametersParser(ParameterList params, throw missing_option_value(it->key); } } - else + else // positional { if (desc.flags & ParameterDesc::Flags::SwitchesOnlyAtStart) only_pos = true;