summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/regex/test/pathology/recursion_test.cpp
blob: c0438e6e7370dfb6438612ea00a8c17c16ec0f46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 *
 * Copyright (c) 1998-2002
 * John Maddock
 *
 * Use, modification and distribution are subject to the 
 * Boost Software License, Version 1.0. (See accompanying file 
 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 *
 */

 /*
  *   LOCATION:    see http://www.boost.org for most recent version.
  *   FILE:        recursion_test.cpp
  *   VERSION:     see <boost/version.hpp>
  *   DESCRIPTION: Test for indefinite recursion and/or stack overrun.
  */

#include <boost/regex.hpp>
#include <boost/detail/lightweight_main.hpp>
#include "../test_macros.hpp"
#include <string>

#ifdef BOOST_INTEL
#pragma warning(disable:1418 981 983 383)
#endif

int cpp_main( int , char* [] )
{
   // this regex will recurse twice for each whitespace character matched:
   boost::regex e("([[:space:]]|.)+");

   std::string bad_text(1024*1024*4, ' ');
   std::string good_text(200, ' ');

   boost::smatch what;

   //
   // Over and over: We want to make sure that after a stack error has
   // been triggered, that we can still conduct a good search and that
   // subsequent stack failures still do the right thing:
   //
   BOOST_CHECK(boost::regex_search(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_search(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_search(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_search(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_search(good_text, what, e));

   BOOST_CHECK(boost::regex_match(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_match(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_match(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_match(good_text, what, e));
   BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
   BOOST_CHECK(boost::regex_match(good_text, what, e));

   return 0;
}