file t.cpp which is compilable and executable:
#include <cppcms/json.h>
#include <iostream>
typedef std::map<std::string,std::string> bts;
int main(int argc,char **argv)
{
std::map<int,std::pair<cppcms::json::array,bts> > ss;
for(int i=1;i <= 5;++i){
auto ret=ss.emplace(std::make_pair(5,std::make_pair(cppcms::json::array(),bts())));
auto &ps=ret.first->second.first;
if(ret.second){ //Insert succeeded.
ps.resize(2);
ps[0]=cppcms::json::array();
auto &sp=ps[0].array();
sp.resize(6);
sp[0]=std::string("a");
sp[1]="b";
sp[2]=true;
sp[3]=0;
sp[4]=12;
//sp[5]=false; //TODO:Why does not crash here?
ps[1]=cppcms::json::array();
cppcms::json::array ts;
ts.push_back(std::string("a"));
ts.push_back(14);
cppcms::json::array params;
for(int j=1;j <= 2;++j){
cppcms::json::array pi;
pi.push_back(std::string("c"));
pi.push_back(1);
params.push_back(pi);
}
if(!params.empty())
ts.push_back(params);
ps.push_back(ts);
sp[5]=false; //TODO:Why crashes here?
}
ps[1].array().push_back(cppcms::json::array());
auto &tb=ps[1].array().back().array();
tb.resize(8);
tb[0]=std::string("a");
tb[1]="a";
tb[2]=30;
tb[3]=cppcms::json::null();
tb[4]="b";
tb[5]="c";
tb[6]=cppcms::json::null();
tb[7]=cppcms::json::null();
}
std::cerr << "done" << std::endl;
return 0;
}
gdb output:
Starting program: /home/u2/tmp/cppcms_json/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
===backtrack===
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007ffff6e1242a in __GI_abort () at abort.c:89
#2 0x00007ffff6e4ec00 in __libc_message (do_abort=do_abort@entry=2,
fmt=fmt@entry=0x7ffff6f43d98 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/posix/libc_fatal.c:175
#3 0x00007ffff6e54fc6 in malloc_printerr (action=3,
str=0x7ffff6f441a0 "malloc(): memory corruption (fast)", ptr=<optimized out>,
ar_ptr=<optimized out>) at malloc.c:5049
#4 0x00007ffff6e57491 in _int_malloc (av=av@entry=0x7ffff7177b00 <main_arena>,
bytes=bytes@entry=56) at malloc.c:3424
#5 0x00007ffff6e58f64 in __GI___libc_malloc (bytes=56) at malloc.c:2928
#6 0x00007ffff77277a8 in operator new(unsigned long) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007ffff7b01b76 in booster::copy_ptr<cppcms::json::value::_data>::copy_ptr (
other=..., this=0x5555557724b8)
at /home/u2/www/resource/src/cppcms/booster/booster/copy_ptr.h:28
#8 cppcms::json::value::copyable::copyable (this=0x5555557724b8, r=...)
at /home/u2/www/resource/src/cppcms/src/json.cpp:311
#9 0x00007ffff7b01c88 in cppcms::json::value::value (other=...,
this=<optimized out>) at /home/u2/www/resource/src/cppcms/cppcms/json.h:515
#10 std::_Construct<cppcms::json::value, cppcms::json::value const&> (
__p=<optimized out>) at /usr/include/c++/6/bits/stl_construct.h:75
#11 std::__uninitialized_copy<false>::__uninit_copy<__gnu_cxx::__normal_iterator<cppcms::json::value const*, std::vector<cppcms::json::value, std::allocator<cppcms::json::value> > >, cppcms::json::value*> (__result=0x5555557724b0, __last=...,
__first=...) at /usr/include/c++/6/bits/stl_uninitialized.h:75
#12 std::uninitialized_copy<__gnu_cxx::__normal_iterator<cppcms::json::value const*, std::vector<cppcms::json::value, std::allocator<cppcms::json::value> > >, cppcms::json::value*> (__result=<optimized out>, __last=..., __first=...)
at /usr/include/c++/6/bits/stl_uninitialized.h:126
#13 std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<cppcms::json::value const*, std::vector<cppcms::json::value, std::allocator<cppcms::json::value> > >, cppcms::json::value*, cppcms::json::value> (__result=<optimized out>, __last=...,
__first=...) at /usr/include/c++/6/bits/stl_uninitialized.h:281
#14 std::vector<cppcms::json::value, std::allocator<cppcms::json::value> >::vector (
__x=..., this=0x555555771560) at /usr/include/c++/6/bits/stl_vector.h:324
#15 cppcms::json::variant::create (other=..., t=<optimized out>,
this=0x555555771560) at /home/u2/www/resource/src/cppcms/src/json.cpp:257
#16 cppcms::json::variant::variant (other=..., this=0x555555771560)
at /home/u2/www/resource/src/cppcms/src/json.cpp:140
#17 cppcms::json::value::_data::_data (this=0x555555771560)
at /home/u2/www/resource/src/cppcms/src/json.cpp:286
#18 booster::copy_ptr<cppcms::json::value::_data>::copy_ptr (other=...,
this=0x555555771b28)
at /home/u2/www/resource/src/cppcms/booster/booster/copy_ptr.h:28
#19 cppcms::json::value::copyable::copyable (this=0x555555771b28, r=...)
at /home/u2/www/resource/src/cppcms/src/json.cpp:311
#20 0x000055555555653d in cppcms::json::value::value (this=0x555555771b28,
other=...) at /usr/local/include/cppcms/json.h:515
#21 0x0000555555558bd3 in std::_Construct<cppcms::json::value, cppcms::json::value const&> (__p=0x555555771b28, __args#0=...)
at /usr/include/c++/6/bits/stl_construct.h:75
#22 0x0000555555559189 in std::__uninitialized_copy<false>::__uninit_copy<cppcms::json::value const*, cppcms::json::value*> (__first=0x555555771c78,
__last=0x555555771c80, __result=0x555555771b20)
at /usr/include/c++/6/bits/stl_uninitialized.h:75
#23 0x0000555555558ec3 in std::uninitialized_copy<cppcms::json::value const*, cppcms::json::value*> (__first=0x555555771c70, __last=0x555555771c80,
__result=0x555555771b20) at /usr/include/c++/6/bits/stl_uninitialized.h:126
#24 0x0000555555558aaf in std::__uninitialized_copy_a<cppcms::json::value const*, cppcms::json::value*, cppcms::json::value> (__first=0x555555771c70,
__last=0x555555771c80, __result=0x555555771b20)
at /usr/include/c++/6/bits/stl_uninitialized.h:281
#25 0x0000555555558212 in std::__uninitialized_move_if_noexcept_a<cppcms::json::value*, cppcms::json::value*, std::allocator<cppcms::json::value> > (
__first=0x555555771c70, __last=0x555555771c80, __result=0x555555771b20,
__alloc=...) at /usr/include/c++/6/bits/stl_uninitialized.h:304
#26 0x00005555555583a1 in std::vector<cppcms::json::value, std::allocator<cppcms::json::value> >::_M_emplace_back_aux<cppcms::json::value>(cppcms::json::value&&) (
this=0x555555772300,
__args#0=<unknown type in /home/u2/tmp/cppcms_json/a.out, CU 0x0, DIE 0xee5e>) at /usr/include/c++/6/bits/vector.tcc:420
#27 0x0000555555557723 in std::vector<cppcms::json::value, std::allocator<cppcms::json::value> >::emplace_back<cppcms::json::value>(cppcms::json::value&&) (
this=0x555555772300,
__args#0=<unknown type in /home/u2/tmp/cppcms_json/a.out, CU 0x0, DIE 0xee5e>) at /usr/include/c++/6/bits/vector.tcc:101
#28 0x0000555555556d54 in std::vector<cppcms::json::value, std::allocator<cppcms::json::value> >::push_back(cppcms::json::value&&) (this=0x555555772300,
__x=<unknown type in /home/u2/tmp/cppcms_json/a.out, CU 0x0, DIE 0xe953>)
at /usr/include/c++/6/bits/stl_vector.h:933
#29 0x0000555555555e0a in main (argc=1, argv=0x7fffffffe398) at t.cpp:39