Fix out of bound read in ParameterParser::get_switch

The empty string case was not correctly handled.
Fixes #1883
This commit is contained in:
Maxime Coste 2018-02-26 15:20:19 +11:00
parent 18f0902824
commit b4dc16010d

View File

@ -59,7 +59,7 @@ Optional<StringView> ParametersParser::get_switch(StringView name) const
for (size_t i = 0; i < m_params.size(); ++i) for (size_t i = 0; i < m_params.size(); ++i)
{ {
const auto& param = m_params[i]; const auto& param = m_params[i];
if (param[0_byte] == '-' and param.substr(1_byte) == name) if (param.substr(0_byte, 1_byte) == "-" and param.substr(1_byte) == name)
return it->value.takes_arg ? m_params[i+1] : StringView{}; return it->value.takes_arg ? m_params[i+1] : StringView{};
if (param == "--") if (param == "--")