Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in split_program_name if the command line is program name only #739

Closed
defisym opened this issue Jun 5, 2022 · 1 comment
Closed

Comments

@defisym
Copy link

defisym commented Jun 5, 2022

auto commandLine="\"C:\\example.exe\""

try {
    app.parse(commandLine, true);
}
catch (const CLI::ParseError& e) {
    //return app.exit(e);
}

split_program_name will throw std::out_of_range exception, if nothing left in command line after removing the program name here:

vals.second = (esp != std::string::npos) ? commandline.substr(esp + 1) : std::string{};

a quick fix is:

trim(commandline);
auto length = commandline.length();
auto esp = commandline.find_first_of(' ', 1);
while(detail::check_path(commandline.substr(0, esp).c_str()) != path_type::file){
......
// strip the program name
vals.second = (esp != std::string::npos) && (esp < length) ? commandline.substr(esp + 1) : std::string{};
@phlptp phlptp mentioned this issue Jun 5, 2022
@phlptp phlptp closed this as completed Jun 6, 2022
@phlptp
Copy link
Collaborator

phlptp commented Jun 6, 2022

Thanks for catching this, the fix has been merged into main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants