[Boost-bugs] [Boost C++ Libraries] #11935: boost::program_options::error_with_option_name.what() throws std::out_of_range when an empty option is used in the command input

Subject: [Boost-bugs] [Boost C++ Libraries] #11935: boost::program_options::error_with_option_name.what() throws std::out_of_range when an empty option is used in the command input
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-01-22 16:11:21


#11935: boost::program_options::error_with_option_name.what() throws
std::out_of_range when an empty option is used in the command input
------------------------------+-----------------------------
 Reporter: mark.incley@… | Owner: vladimir_prus
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: program_options
  Version: Boost 1.60.0 | Severity: Problem
 Keywords: program_options |
------------------------------+-----------------------------
 Hi,

 After accidentally typing "-v . -" (without the quotes) into a Windows
 command line app written with boost::po, it crashed. The app's catch block
 (code below) calls boost::po::error_with_option_name.what() and this
 subsequently throws std::out_of_range().

 It appears as though the empty option "-" confuses
 boost::program_options::strip_prefixes(const std::string& text) which is
 called with text value of "-", resulting in text.substr being called with
 a value of npos:

 {{{
   inline std::string strip_prefixes(const std::string& text)
     {
         // "--foo-bar" -> "foo-bar"[[BR]]
         return text.substr(text.find_first_not_of("-/"));
     }
 }}}

 Here's my code.


 {{{
 po::variables_map vm;
         po::options_description desc("Options");
         desc.add_options()
                 ("folder,f", po::wvalue<wstring>()->required(),
 "Specify the name of the folder containing the C++ projects to check")
                 ("list,l", "List the project file names as
 they're checked")
                 ("verbose,v", "Verbose; Show the node values when
 finding non-SAK SCC values")
                 ("help,?", "Show usage information")
                 ;

         po::positional_options_description pod;
         pod.add("folder", -1);

         try
         {
                 po::store(po::wcommand_line_parser(argc,
 argv).options(desc).positional(pod).run(), vm);
                 po::notify(vm);
         }
         catch (const boost::program_options::error & e)
         {
                 cerr << w32::fg_red << e.what() << w32::restore << endl;
                 return ERROR_UNHANDLED_EXCEPTION;
         }

 }}}


 I am using Boost 1.60 on Windows 7 (64-bit) with Visual Studio 2015 Update
 1.

 Cheers[[BR]]
 Mark.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11935>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC