From 026c527d8d459f69b84557d08dd2d70d824e167b Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 24 Apr 2006 08:00:13 +0000 Subject: [PATCH 001/144] Workaround "interator incremented past the end" assertion in MSVC-8.0. [SVN r33776] --- src/options_description.cpp | 13 ++++++------- test/options_description_test.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/options_description.cpp b/src/options_description.cpp index 6408502..7ce5aad 100644 --- a/src/options_description.cpp +++ b/src/options_description.cpp @@ -390,13 +390,12 @@ namespace boost { namespace program_options { } } - string::const_iterator line_end; - - line_end = line_begin + line_length; - if (line_end > par_end) - { - line_end = par_end; - } + // Take care to never increment the iterator past + // the end, since MSVC 8.0 (brokenly), assumes that + // doing that, even if no access happens, is a bug. + unsigned remaining = distance(line_begin, par_end); + string::const_iterator line_end = line_begin + + ((remaining < line_length) ? remaining : line_length); // prevent chopped words // Is line_end between two non-space characters? diff --git a/test/options_description_test.cpp b/test/options_description_test.cpp index 60a4ebb..d5ec259 100644 --- a/test/options_description_test.cpp +++ b/test/options_description_test.cpp @@ -15,6 +15,7 @@ using namespace boost; #include #include +#include using namespace std; void test_type() @@ -61,9 +62,25 @@ void test_approximation() // BOOST_CHECK(*(++a.begin()) == "foo"); } +void test_formatting() +{ + // Long option descriptions used to crash on MSVC-8.0. + options_description desc; + desc.add_options()( + "test", new untyped_value(), + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo" + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo" + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo" + "foo foo foo foo foo foo foo foo foo foo foo foo foo foo"); + + stringstream ss; + ss << desc; +} + int test_main(int, char* []) { test_type(); test_approximation(); + test_formatting(); return 0; } From 3765e8e8e948c4b9f463f8353a0df0c08ebeb8cf Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 24 Apr 2006 08:25:12 +0000 Subject: [PATCH 002/144] Fix accesses to first element of an empty string. Thanks to Olaf van der Spek for the report. [SVN r33778] --- src/value_semantic.cpp | 7 +++++-- test/parsers_test.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/value_semantic.cpp b/src/value_semantic.cpp index 9298536..0cdf699 100644 --- a/src/value_semantic.cpp +++ b/src/value_semantic.cpp @@ -170,9 +170,12 @@ namespace boost { namespace program_options { { check_first_occurrence(v); string s(get_single_string(xs)); - if (*s.begin() == '\'' && *s.rbegin() == '\'' || - *s.begin() == '"' && *s.rbegin() == '"') + if (!s.empty() && ( + (*s.begin() == '\'' && *s.rbegin() == '\'' || + *s.begin() == '"' && *s.rbegin() == '"'))) + { v = any(s.substr(1, s.size()-2)); + } else v = any(s); } diff --git a/test/parsers_test.cpp b/test/parsers_test.cpp index 17aaf92..e292d7d 100644 --- a/test/parsers_test.cpp +++ b/test/parsers_test.cpp @@ -133,6 +133,16 @@ void test_command_line() check_value(a4[0], "foo", "4"); check_value(a4[1], "bar", "11"); + // Check that we don't crash on empty values of type 'string' + char* cmdline4[] = {"", "--open", ""}; + options_description desc2; + desc2.add_options() + ("open", po::value()) + ; + variables_map vm; + po::store(po::parse_command_line(3, cmdline4, desc2), vm); + + } From ac6de20f85a5afd0bc937fc974420445b414fa43 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 24 Apr 2006 08:51:38 +0000 Subject: [PATCH 003/144] Clarify special handling of vectors. [SVN r33780] --- doc/tutorial.xml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/tutorial.xml b/doc/tutorial.xml index 3d3fb84..4a89eba 100644 --- a/doc/tutorial.xml +++ b/doc/tutorial.xml @@ -96,7 +96,7 @@ Compression level was set to 10. An option value, surely, can have other types than int, and can have other interesting properties, which we'll discuss right now. The complete version of the code snipped below can be found in - "example/options_description.cpp". + example/options_description.cpp. Imagine we're writing a compiler. It should take the optimization level, a number of include paths, and a number of input files, and perform some @@ -115,21 +115,29 @@ desc.add_options() - The "--help" option should be familiar from the previous example. - It's a good idea to have this option in all cases. + The "help" option should be familiar from + the previous example. It's a good idea to have this option in all cases. + - The "optimization" option shows two new features. First, we specify + The "optimization" option shows two new features. First, we specify the address of the variable(&opt). After storing values, that variable will have the value of the option. Second, we specify a default value of 10, which will be used if no value is specified by the user. - The "include-path" option is an example of the only case where - the interface of the options_description class serves only one + The "include-path" option is an example of the + only case where the interface of the options_description + class serves only one source -- the command line. Users typically like to use short option names for common options, and the "include-path,I" name specifies that short option name is "I". So, both "--include-path" and "-I" can be used. + + Note also that the type of the "include-path" + option is std::vector. The library provides special + support for vectors -- it will be possible to specify the option several + times, and all specified values will be collected in one vector. + The "input-file" option specifies the list of files to process. That's okay for a start, but, of course, writing something like: @@ -337,7 +345,7 @@ Optimization level is 4