Menu

#17 Parsing error: erroneous '.exe' stripping throws std::out_of_range

1.4
closed-fixed
bug (1)
5
2021-02-02
2021-01-28
No

When using tclap on Linux (Ubuntu on WSL2), I experienced the following exception:

terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::erase: __pos (which is 18446744073709551615) > this->size() (which is 3)

By debugging, I traced the problem to this line:

// CmdLineOutput.h, lines 101-102 p = s.rfind(".exe"); if (p == s.length() - 4) {

The problem happens because my executable's name has 3 charactes, so s.length() - 4 underflows into std::string::npos. The fix is simple:

// CmdLineOutput.h, lines 101-102 p = s.rfind(".exe"); if (p != std::string::npos and p == s.length() - 4) {

Discussion

  • Franco Vieira de Souza

    Edit: sorry for the badly formatted message, I'm not used to sourceforge. Here's another go:

    Exception message:

    terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::erase: __pos (which is 18446744073709551615) > this->size() (which is 3)
    

    Offending code:

    // CmdLineOutput.h, lines 101-102
    p = s.rfind(".exe");
    if (p == s.length() - 4) {
    

    Fix:

    // CmdLineOutput.h, lines 101-102
    p = s.rfind(".exe");
    if (p != std::string::npos and p == s.length() - 4) {
    
     
  • Daniel Aarno

    Daniel Aarno - 2021-01-28
    • assigned_to: Daniel Aarno
     
  • Daniel Aarno

    Daniel Aarno - 2021-01-28

    Thank, I can confirm this. A fix should be forthcoming (but by all means, do apply your patch locally for now - or just check if the length is < 4 and return even before the call to rfind)

     
  • Daniel Aarno

    Daniel Aarno - 2021-02-02
    • status: open --> closed-fixed
     
  • Daniel Aarno

    Daniel Aarno - 2021-02-02

    Fixed in [57a98f] (with a follow up fix for Windows in [f73351])

     

    Related

    Commit: [57a98f]
    Commit: [f73351]


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.