Menu

#30 Check arguments vector is not empty before accessing first element

1.2.x
closed-fixed
None
5
2020-12-30
2020-12-10
No

I'm using TCLAP on Debian (libtclap-dev 1.2.2-1+b1) and I use it to parse messages I send between long-running programs. I put arguments in a std::vector<std::string> and use CmdLine::parse to parse it.
I found that if the vector is empty I get a segmentation fault when CmdLine::parse calls args.front();
I think it would be good if the function would instead throw an exception:</std::string>

if (args.empty()) {
throw CmdLineParseException("The args vector must not be empty, the first entry should contain the program's name.");
}

Discussion

  • Alexander Brock

    Alexander Brock - 2020-12-10

    I messed up the title, I wanted "Check arguments vector is not empty before accessing first element" but it seems I can't edit titles

     
  • Daniel Aarno

    Daniel Aarno - 2020-12-11
    • summary: Check --> Check arguments vector is not empty before accessing first element
    • assigned_to: Daniel Aarno
     
  • Daniel Aarno

    Daniel Aarno - 2020-12-11

    Sounds reasonable. This will never happen when argv/c comes from the command line, but I don't see why we could not add this check.

     
  • Daniel Aarno

    Daniel Aarno - 2020-12-30
    • status: open --> closed-fixed
     

Log in to post a comment.