Skip to content

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

@defisym

Description

@defisym
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{};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions