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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user