2003-05-17 11:55:51 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1998-2002
|
|
|
|
* Dr John Maddock
|
|
|
|
*
|
2003-10-04 11:29:20 +00:00
|
|
|
* Use, modification and distribution are subject to the
|
2003-09-30 13:02:51 +00:00
|
|
|
* Boost Software License, Version 1.0. (See accompanying file
|
|
|
|
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
2003-05-17 11:55:51 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 <string>
|
|
|
|
#include <boost/regex.hpp>
|
|
|
|
#include <boost/test/test_tools.hpp>
|
|
|
|
|
2003-08-12 11:24:09 +00:00
|
|
|
int test_main( int , char* [] )
|
2003-05-17 11:55:51 +00:00
|
|
|
{
|
|
|
|
// 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;
|
2003-05-19 11:56:17 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 13:02:51 +00:00
|
|
|
|