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

core dump on optional arg #10

Closed
rianquinn opened this issue May 3, 2019 · 2 comments
Closed

core dump on optional arg #10

rianquinn opened this issue May 3, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@rianquinn
Copy link

if I add an optional arg with a single "-" something like "-o" but don't define how to handle it, I get a seg fault. If I handle it, it's fine. The issue is if the user ads a single - argument that is not supported it will cause a seg fault and there is nothing I can do on my end

@p-ranav p-ranav self-assigned this May 3, 2019
@p-ranav p-ranav added bug Something isn't working and removed bug Something isn't working labels May 3, 2019
@p-ranav
Copy link
Owner

p-ranav commented May 3, 2019

Can you provide a code snippet so I can reproduce the core dump? Please explain what you mean by "but don't define how to handle it"

@rianquinn
Copy link
Author

This is the code that I am using. If I pass "-o" and nothing else, I get a core dump

    argparse::ArgumentParser bfm("bfm");

    bfm.add_argument("-l","--load")
        .help("load a VMM into the kernel");

    bfm.add_argument("-x", "--start")
        .default_value(false)
        .implicit_value(true)
        .help("start a previously loaded VMM");

    bfm.add_argument("-d", "--dump")
        .default_value(false)
        .implicit_value(true)
        .help("output the contents of the VMM's debug buffer");

    bfm.add_argument("-s", "--stop")
        .default_value(false)
        .implicit_value(true)
        .help("stop a previously started VMM");

    bfm.add_argument("-u", "--unload")
        .default_value(false)
        .implicit_value(true)
        .help("unload a previously loaded VMM");

    bfm.add_argument("-m", "--mem")
        .default_value(64ULL)
        .action([](const std::string& val) { return std::stoull(val); })
        .help("memory in MB to give the VMM when loading");

    bfm.parse_args(argc, argv);

    if (!bfm.get<std::string>("--load").empty()) {
        this->load_vmm(
            bfm.get<std::string>("--load"),
            bfm.get<unsigned long long>("--mem")
        );
    }

    if (bfm.get<bool>("--start")) {
        this->start_vmm();
    }

    if (bfm.get<bool>("--dump")) {
        this->dump_vmm();
    }

    if (bfm.get<bool>("--stop")) {
        this->stop_vmm();
    }

    if (bfm.get<bool>("--unload")) {
        this->unload_vmm();
    }

@p-ranav p-ranav added the bug Something isn't working label May 4, 2019
@p-ranav p-ranav closed this as completed May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants