From 7759821b13e74c7aac05d4b7fb67de599cab65e9 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 13 Sep 2021 00:58:51 +0200 Subject: [PATCH] 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. --- src/util/argparser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/argparser.cpp b/src/util/argparser.cpp index c8fec8e..b173536 100644 --- a/src/util/argparser.cpp +++ b/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;