From 02c6228c779f52e1796044fec540a60c4475a841 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sun, 11 Dec 2005 17:34:32 +0000 Subject: [PATCH] Fix /analyse errors from VC8. Update test cases appropriately. [SVN r31988] --- src/posix_api.cpp | 27 +++++++-- src/wide_posix_api.cpp | 28 +++++++-- test/regress/test_deprecated.cpp | 97 ++++++++++++++++++++++++------ test/regress/test_tricky_cases.cpp | 24 ++++++++ 4 files changed, 149 insertions(+), 27 deletions(-) diff --git a/src/posix_api.cpp b/src/posix_api.cpp index eb82f1b9..64cb5dc2 100644 --- a/src/posix_api.cpp +++ b/src/posix_api.cpp @@ -37,10 +37,29 @@ namespace{ unsigned int magic_value = 25631; -const char* names[] = {"REG_NOERROR", "REG_NOMATCH", "REG_BADPAT", "REG_ECOLLATE", - "REG_ECTYPE", "REG_EESCAPE", "REG_ESUBREG", "REG_EBRACK", - "REG_EPAREN", "REG_EBRACE", "REG_BADBR", "REG_ERANGE", - "REG_ESPACE", "REG_BADRPT", "REG_EMPTY", "REG_E_UNKNOWN"}; +const char* names[] = { + "REG_NOERROR", + "REG_NOMATCH", + "REG_BADPAT", + "REG_ECOLLATE", + "REG_ECTYPE", + "REG_EESCAPE", + "REG_ESUBREG", + "REG_EBRACK", + "REG_EPAREN", + "REG_EBRACE", + "REG_BADBR", + "REG_ERANGE", + "REG_ESPACE", + "REG_BADRPT", + "REG_EEND", + "REG_ESIZE", + "REG_ERPAREN", + "REG_EMPTY", + "REG_ECOMPLEXITY", + "REG_ESTACK", + "REG_E_UNKNOWN", +}; } // namespace BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA* expression, const char* ptr, int f) diff --git a/src/wide_posix_api.cpp b/src/wide_posix_api.cpp index 97a2225d..0673e17d 100644 --- a/src/wide_posix_api.cpp +++ b/src/wide_posix_api.cpp @@ -44,11 +44,29 @@ namespace { unsigned int wmagic_value = 28631; -const wchar_t* wnames[] = {L"REG_NOERROR", L"REG_NOMATCH", L"REG_BADPAT", L"REG_ECOLLATE", - L"REG_ECTYPE", L"REG_EESCAPE", L"REG_ESUBREG", L"REG_EBRACK", - L"REG_EPAREN", L"REG_EBRACE", L"REG_BADBR", L"REG_ERANGE", - L"REG_ESPACE", L"REG_BADRPT", L"REG_EMPTY", L"REG_E_UNKNOWN"}; - +const wchar_t* wnames[] = { + L"REG_NOERROR", + L"REG_NOMATCH", + L"REG_BADPAT", + L"REG_ECOLLATE", + L"REG_ECTYPE", + L"REG_EESCAPE", + L"REG_ESUBREG", + L"REG_EBRACK", + L"REG_EPAREN", + L"REG_EBRACE", + L"REG_BADBR", + L"REG_ERANGE", + L"REG_ESPACE", + L"REG_BADRPT", + L"REG_EEND", + L"REG_ESIZE", + L"REG_ERPAREN", + L"REG_EMPTY", + L"REG_ECOMPLEXITY", + L"REG_ESTACK", + L"REG_E_UNKNOWN", +}; } BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wchar_t* ptr, int f) diff --git a/test/regress/test_deprecated.cpp b/test/regress/test_deprecated.cpp index ef10a765..171a3b56 100644 --- a/test/regress/test_deprecated.cpp +++ b/test/regress/test_deprecated.cpp @@ -23,6 +23,13 @@ #pragma warning(disable:4267) #endif +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ + using ::atoi; + using ::wcstol; +} +#endif + int get_posix_compile_options(boost::regex_constants::syntax_option_type opts) { using namespace boost; @@ -93,19 +100,23 @@ void test_deprecated(const char&, const test_regex_search_tag&) return; } // try and find the first occurance: - boost::regmatch_t matches[50]; - if(boost::regexecA(&re, search_text.c_str(), 50, matches, posix_match_options) == 0) + static const unsigned max_subs = 100; + boost::regmatch_t matches[max_subs]; + if(boost::regexecA(&re, search_text.c_str(), max_subs, matches, posix_match_options) == 0) { int i = 0; while(results[2*i] != -2) { - if(results[2*i] != matches[i].rm_so) + if(max_subs > i) { - BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", char); - } - if(results[2*i+1] != matches[i].rm_eo) - { - BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", char); + if(results[2*i] != matches[i].rm_so) + { + BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", char); + } + if(results[2*i+1] != matches[i].rm_eo) + { + BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", char); + } } ++i; } @@ -213,19 +224,23 @@ void test_deprecated(const wchar_t&, const test_regex_search_tag&) return; } // try and find the first occurance: - boost::regmatch_t matches[50]; - if(boost::regexecW(&re, search_text.c_str(), 50, matches, posix_match_options) == 0) + static const unsigned max_subs = 100; + boost::regmatch_t matches[max_subs]; + if(boost::regexecW(&re, search_text.c_str(), max_subs, matches, posix_match_options) == 0) { int i = 0; while(results[2*i] != -2) { - if(results[2*i] != matches[i].rm_so) + if(max_subs > i) { - BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", wchar_t); - } - if(results[2*i+1] != matches[i].rm_eo) - { - BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", wchar_t); + if(results[2*i] != matches[i].rm_so) + { + BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", wchar_t); + } + if(results[2*i+1] != matches[i].rm_eo) + { + BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", wchar_t); + } } ++i; } @@ -253,11 +268,34 @@ void test_deprecated(const char&, const test_invalid_regex_tag&) // OK try and compile the expression: boost::regex_tA re; - if(boost::regcompA(&re, expression.c_str(), posix_options) == 0) + int code = boost::regcompA(&re, expression.c_str(), posix_options); + if(code == 0) { boost::regfreeA(&re); BOOST_REGEX_TEST_ERROR("Expression : \"" << expression.c_str() << "\" unexpectedly compiled with the POSIX C API.", char); } + else + { + char buf[100]; + int s = boost::regerrorA(code, &re, 0, 0); + if(s < 100) + s = boost::regerrorA(code, &re, buf, 100); + s = boost::regerrorA(code | boost::REG_ITOA, &re, 0, 0); + if(s < 100) + { + s = boost::regerrorA(code | boost::REG_ITOA, &re, buf, 100); + re.re_endp = buf; + s = boost::regerrorA(code | boost::REG_ATOI, &re, buf, 100); + if(s) + { + int code2 = std::atoi(buf); + if(code2 != code) + { + BOOST_REGEX_TEST_ERROR("Got a bad error code from regerrA with REG_ATOI set: ", char); + } + } + } + } // // now try the RegEx class: // @@ -307,10 +345,33 @@ void test_deprecated(const wchar_t&, const test_invalid_regex_tag&) // OK try and compile the expression: boost::regex_tW re; - if(boost::regcompW(&re, expression.c_str(), posix_options) == 0) + int code = boost::regcompW(&re, expression.c_str(), posix_options); + if(code == 0) { boost::regfreeW(&re); BOOST_REGEX_TEST_ERROR("Expression : \"" << expression.c_str() << "\" unexpectedly compiled with the POSIX C API.", wchar_t); } + else + { + wchar_t buf[100]; + int s = boost::regerrorW(code, &re, 0, 0); + if(s < 100) + s = boost::regerrorW(code, &re, buf, 100); + s = boost::regerrorW(code | boost::REG_ITOA, &re, 0, 0); + if(s < 100) + { + s = boost::regerrorW(code | boost::REG_ITOA, &re, buf, 100); + re.re_endp = buf; + s = boost::regerrorW(code | boost::REG_ATOI, &re, buf, 100); + if(s) + { + long code2 = std::wcstol(buf, 0, 10); + if(code2 != code) + { + BOOST_REGEX_TEST_ERROR("Got a bad error code from regerrW with REG_ATOI set: ", char); + } + } + } + } #endif } diff --git a/test/regress/test_tricky_cases.cpp b/test/regress/test_tricky_cases.cpp index 87de1cd6..e53024b3 100644 --- a/test/regress/test_tricky_cases.cpp +++ b/test/regress/test_tricky_cases.cpp @@ -75,6 +75,30 @@ void test_tricky_cases() TEST_REGEX_SEARCH("a(bbb+|bb+|b)bb", perl, "abbb", match_default, make_array(0, 4, 1, 2, -2, -2)); TEST_REGEX_SEARCH("(.*).*", perl, "abcdef", match_default, make_array(0, 6, 0, 6, -2, 6, 6, 6, 6, -2, -2)); TEST_REGEX_SEARCH("(a*)*", perl, "bc", match_default, make_array(0, 0, 0, 0, -2, 1, 1, 1, 1, -2, 2, 2, 2, 2, -2, -2)); + TEST_REGEX_SEARCH("Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+", perl, "bc", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+", perl, "aaa", match_default, + make_array(0, 3, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 3, + -2, -2)); + TEST_REGEX_SEARCH("Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+", + perl, "Zaaa", match_default, + make_array(0, 4, + 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, + -2, -2)); TEST_REGEX_SEARCH("xyx*xz", perl, "xyxxxxyxxxz", match_default, make_array(5, 11, -2, -2)); // do we get the right subexpression when it is used more than once? TEST_REGEX_SEARCH("a(b|c)*d", perl, "ad", match_default, make_array(0, 2, -1, -1, -2, -2));