Ticket #5520: trigger_bug.cpp

File trigger_bug.cpp, 1.2 KB (added by Laszlo Kustra <kl223hun@…>, 11 years ago)

Short example to trigger segfault in read_json.

Line 
1#include <boost/property_tree/ptree.hpp>
2#include <boost/property_tree/json_parser.hpp>
3#include <boost/thread.hpp>
4#include <iostream>
5#include <string>
6
7struct read_t
8{
9 read_t(const std::string &_js) : js(_js)
10 {
11 }
12
13 void operator()() const
14 {
15 std::istringstream ijs;
16 while (true)
17 {
18 ijs.str(js);
19 boost::property_tree::ptree pt;
20 boost::property_tree::read_json(ijs, pt);
21 std::cout << "." << std::flush;
22 }
23 }
24
25 const std::string js;
26};
27
28
29int main()
30{
31 const std::string js = "\
32 {\
33 \"glossary\":{\
34 \"title\":\"example glossary\",\
35 \"GlossDiv\":{\
36 \"title\":\"S\",\
37 \"GlossList\":{\
38 \"GlossEntry\":{\
39 \"ID\":\"SGML\",\
40 \"SortAs\":\"SGML\",\
41 \"GlossTerm\":\"Standard Generalized Markup Language\",\
42 \"Acronym\":\"SGML\",\
43 \"Abbrev\":\"ISO 8879:1986\",\
44 \"GlossDef\":{\
45 \"para\":\"A meta-markup language.\",\
46 \"GlossSeeAlso\":[\
47 \"GML\",\
48 \"XML\"\
49 ]\
50 },\
51 \"GlossSee\":\"markup\"\
52 }\
53 }\
54 }\
55 }\
56 }\
57 ";
58
59 boost::thread t1((read_t(js)));
60 boost::thread t2((read_t(js))); // comment out this line and the program runs fine
61 t1.join(); // never stop
62 return 0;
63}