| 1 | /*============================================================================= |
|---|
| 2 | Copyright (c) 2004 Joao Abecasis |
|---|
| 3 | http://spirit.sourceforge.net/ |
|---|
| 4 | |
|---|
| 5 | Use, modification and distribution is subject to the Boost Software |
|---|
| 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | =============================================================================*/ |
|---|
| 9 | |
|---|
| 10 | #define BOOST_SPIRIT_ASSERT_EXCEPTION ::spirit_exception |
|---|
| 11 | |
|---|
| 12 | struct spirit_exception |
|---|
| 13 | { |
|---|
| 14 | spirit_exception(char const * msg) |
|---|
| 15 | : message(msg) |
|---|
| 16 | { |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | char const * message; |
|---|
| 20 | }; |
|---|
| 21 | |
|---|
| 22 | #include <boost/spirit/core/scanner/scanner.hpp> |
|---|
| 23 | #include <boost/spirit/symbols/impl/tst.ipp> |
|---|
| 24 | #include <boost/utility/addressof.hpp> |
|---|
| 25 | |
|---|
| 26 | #include <boost/detail/lightweight_test.hpp> |
|---|
| 27 | |
|---|
| 28 | typedef char char_type; |
|---|
| 29 | typedef char const * iterator; |
|---|
| 30 | |
|---|
| 31 | char_type data_[] = "whatever"; |
|---|
| 32 | |
|---|
| 33 | iterator begin = data_; |
|---|
| 34 | iterator end = data_ |
|---|
| 35 | + sizeof(data_)/sizeof(char_type); // Yes, this is an intentional bug ;) |
|---|
| 36 | |
|---|
| 37 | char_type data2_[] = "\0something"; |
|---|
| 38 | iterator begin2 = data2_; |
|---|
| 39 | iterator end2 = data2_ + sizeof(data2_)/sizeof(char_type) - 1; |
|---|
| 40 | |
|---|
| 41 | int main() |
|---|
| 42 | { |
|---|
| 43 | typedef boost::spirit::scanner<> scanner; |
|---|
| 44 | typedef boost::spirit::impl::tst<void *, char_type> symbols; |
|---|
| 45 | |
|---|
| 46 | symbols symbols_; |
|---|
| 47 | |
|---|
| 48 | try |
|---|
| 49 | { |
|---|
| 50 | // It is not ok to add strings containing the null character. |
|---|
| 51 | symbols_.add(begin, end, (void*) boost::addressof(symbols_)); |
|---|
| 52 | BOOST_TEST(0); |
|---|
| 53 | } |
|---|
| 54 | catch (spirit_exception &e) |
|---|
| 55 | { |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | try |
|---|
| 59 | { |
|---|
| 60 | // It is not ok to add strings containing the null character. |
|---|
| 61 | symbols_.add(begin2, end2, (void*) boost::addressof(symbols_)); |
|---|
| 62 | BOOST_TEST(0); |
|---|
| 63 | } |
|---|
| 64 | catch (spirit_exception &e) |
|---|
| 65 | { |
|---|
| 66 | } |
|---|
| 67 | return boost::report_errors(); |
|---|
| 68 | } |
|---|