From 3e1d2603e63cb500c3a95533f7ff6c12033a9f09 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Fri, 21 Jul 2017 18:30:47 +0300 Subject: [PATCH] Fix out-of-range error Closes #31. --- include/boost/program_options/errors.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/boost/program_options/errors.hpp b/include/boost/program_options/errors.hpp index 97a69e4..2df4096 100644 --- a/include/boost/program_options/errors.hpp +++ b/include/boost/program_options/errors.hpp @@ -26,7 +26,12 @@ namespace boost { namespace program_options { inline std::string strip_prefixes(const std::string& text) { // "--foo-bar" -> "foo-bar" - return text.substr(text.find_first_not_of("-/")); + std::string::size_type i = text.find_first_not_of("-/"); + if (i == std::string::npos) { + return text; + } else { + return text.substr(i); + } } /** Base class for all errors in the library. */