Skip to content

Commit

Permalink
Fixed crash when command line parameter is at the end of commandline
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Oct 28, 2024
1 parent acd92a4 commit 7ceed93
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/scriptProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,15 +983,18 @@ std::string get_command_line() {
}

std::optional<std::string> getCommandLineParam(std::string_view needle) {
std::string commandLine = get_command_line();
std::string commandLineF = get_command_line();
std::string_view commandLine(commandLineF);
const auto found = commandLine.find(needle);
if (found != std::string::npos) {
const auto spacePos = commandLine.find(' ', found + needle.length() + 1);
const auto valueLength = spacePos - (found + needle.length() + 1);
auto adapterStr = commandLine.substr(found + needle.length() + 1, valueLength);
if (adapterStr.back() == '"')
adapterStr = adapterStr.substr(0, adapterStr.length() - 1);
return adapterStr;
auto parameter = commandLine.substr(found);

// Find end of parameter
parameter = parameter.substr(0, parameter.find(' '));
auto adapterStr = parameter.substr(std::min(parameter.length(), needle.length() + 1));
//if (adapterStr.back() == '"') // Filtering away quotes, but we don't do that anymore
// adapterStr = adapterStr.substr(0, adapterStr.length() - 1);
return std::string(adapterStr);
}

if (!json.empty() && json.contains(needle.substr(1))) {
Expand Down

0 comments on commit 7ceed93

Please sign in to comment.