recursion_test.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE: recursion_test.cpp
  14. * VERSION: see <boost/version.hpp>
  15. * DESCRIPTION: Test for indefinite recursion and/or stack overrun.
  16. */
  17. #include <boost/regex.hpp>
  18. #include <boost/detail/lightweight_main.hpp>
  19. #include "../test_macros.hpp"
  20. #include <string>
  21. #ifdef BOOST_INTEL
  22. #pragma warning(disable:1418 981 983 383)
  23. #endif
  24. int cpp_main( int , char* [] )
  25. {
  26. // this regex will recurse twice for each whitespace character matched:
  27. boost::regex e("([[:space:]]|.)+");
  28. std::string bad_text(1024*1024*4, ' ');
  29. std::string good_text(200, ' ');
  30. boost::smatch what;
  31. //
  32. // Over and over: We want to make sure that after a stack error has
  33. // been triggered, that we can still conduct a good search and that
  34. // subsequent stack failures still do the right thing:
  35. //
  36. BOOST_CHECK(boost::regex_search(good_text, what, e));
  37. BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
  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(boost::regex_match(good_text, what, e));
  46. BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
  47. BOOST_CHECK(boost::regex_match(good_text, what, e));
  48. BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
  49. BOOST_CHECK(boost::regex_match(good_text, what, e));
  50. BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
  51. BOOST_CHECK(boost::regex_match(good_text, what, e));
  52. BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
  53. BOOST_CHECK(boost::regex_match(good_text, what, e));
  54. return 0;
  55. }