| 1 | /* |
|---|
| 2 | * |
|---|
| 3 | * Copyright (c) 1998-2002 |
|---|
| 4 | * John Maddock |
|---|
| 5 | * |
|---|
| 6 | * Use, modification and distribution are subject to the |
|---|
| 7 | * Boost Software License, Version 1.0. (See accompanying file |
|---|
| 8 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 9 | * |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | /* |
|---|
| 13 | * LOCATION: see http://www.boost.org for most recent version. |
|---|
| 14 | * FILE: recursion_test.cpp |
|---|
| 15 | * VERSION: see <boost/version.hpp> |
|---|
| 16 | * DESCRIPTION: Test for indefinite recursion and/or stack overrun. |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #include <string> |
|---|
| 20 | #include <boost/regex.hpp> |
|---|
| 21 | #include <boost/test/test_tools.hpp> |
|---|
| 22 | |
|---|
| 23 | int test_main( int , char* [] ) |
|---|
| 24 | { |
|---|
| 25 | // this regex will recurse twice for each whitespace character matched: |
|---|
| 26 | boost::regex e("([[:space:]]|.)+"); |
|---|
| 27 | |
|---|
| 28 | std::string bad_text(1024*1024*4, ' '); |
|---|
| 29 | std::string good_text(200, ' '); |
|---|
| 30 | |
|---|
| 31 | boost::smatch what; |
|---|
| 32 | |
|---|
| 33 | // |
|---|
| 34 | // Over and over: We want to make sure that after a stack error has |
|---|
| 35 | // been triggered, that we can still conduct a good search and that |
|---|
| 36 | // subsequent stack failures still do the right thing: |
|---|
| 37 | // |
|---|
| 38 | BOOST_CHECK(boost::regex_search(good_text, what, e)); |
|---|
| 39 | BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error); |
|---|
| 40 | BOOST_CHECK(boost::regex_search(good_text, what, e)); |
|---|
| 41 | BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error); |
|---|
| 42 | BOOST_CHECK(boost::regex_search(good_text, what, e)); |
|---|
| 43 | BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error); |
|---|
| 44 | BOOST_CHECK(boost::regex_search(good_text, what, e)); |
|---|
| 45 | BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error); |
|---|
| 46 | BOOST_CHECK(boost::regex_search(good_text, what, e)); |
|---|
| 47 | |
|---|
| 48 | BOOST_CHECK(boost::regex_match(good_text, what, e)); |
|---|
| 49 | BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error); |
|---|
| 50 | BOOST_CHECK(boost::regex_match(good_text, what, e)); |
|---|
| 51 | BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error); |
|---|
| 52 | BOOST_CHECK(boost::regex_match(good_text, what, e)); |
|---|
| 53 | BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error); |
|---|
| 54 | BOOST_CHECK(boost::regex_match(good_text, what, e)); |
|---|
| 55 | BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error); |
|---|
| 56 | BOOST_CHECK(boost::regex_match(good_text, what, e)); |
|---|
| 57 | |
|---|
| 58 | return 0; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | #include <boost/test/included/test_exec_monitor.hpp> |
|---|