Browse Source

Util: Fix string_view substring selection

Unlike std::basic_string::data() and string literals, data() may return
a pointer to a buffer that is not null-terminated. Therefore it is
typically a mistake to pass data() to a routine that takes just a const
CharT* and expects a null-terminated string.

The bug was calling string_view .data() after calling substr() that ends
before the null terminator, as it will just return the entire
string_view.
master
Riyyi 3 years ago
parent
commit
7759821b13
  1. 2
      src/util/argparser.cpp

2
src/util/argparser.cpp

@ -130,7 +130,7 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next)
{
bool result = true;
std::string_view name = option.substr(0, option.find_first_of('='));
std::string name = std::string(option.substr(0, option.find_first_of('=')));
std::string_view value = option.substr(option.find_first_of('=') + 1);
bool argumentProvided = true;

Loading…
Cancel
Save