m.
L.Suresh wrote:
Hi, I'm getting a segmentation fault in my program when using std::ostringstream.
Code excertps:
std::ostringstream ostr; ostr << pInfo.getPacketId(); // <-- Offending line. calls op<<(long)
... Output few more strings .....
std::cout << ostr.str() << std::endl
GDB: Stack trace
#0 0x0075cdb2 in _int_malloc () from /lib/tls/libc.so.6 #1 0x0075c10d in malloc () from /lib/tls/libc.so.6 #2 0x00b7c80e in operator new(unsigned) () from /usr/lib/libstdc++.so.5 #3 0x00b68c49 in std::__default_alloc_template<true, 0>::allocate(unsigned) () from /usr/lib/libstdc++.so.5 #4 0x00b6e678 in std::string::_Rep::_S_create(unsigned, std::allocator<char> const&) () from /usr/lib/libstdc++.so.5 #5 0x00b6e749 in std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned) () from /usr/lib/libstdc++.so.5 #6 0x00b6c3bd in std::string::reserve(unsigned) () from /usr/lib/libstdc++.so.5 #7 0x00b6347f in std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::overflow(int) () from /usr/lib/libstdc++.so.5 #8 0x00b69ee4 in std::basic_streambuf<char, std::char_traits<char>
::xsputn(char const*, int) () from /usr/lib/libstdc++.so.5
#9 0x00b499ff in std::ostreambuf_iterator<char, std::char_traits<char>
std::num_put<char, std::ostreambuf_iterator<char,
std::char_traits<char> >
::_M_convert_int<long>(std::ostreambuf_iterator<char,
std::char_traits<char> >, std::ios_base&, char, long) const () from /usr/lib/libstdc++.so.5 #10 0x00b495e0 in std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const () from /usr/lib/libstdc++.so.5 #11 0x00b5ef9c in std::ostream::operator<<(long) () #12 0x0806a99b in Engine::NullEngine::analyze(NA::PacketInfo const&) ( this=0x8f9c860, pInfo=@0x8fe3058) at packetinfo.h:146 #13 0x080721c6 in App::WorkerThreadTask::run(Thread*) (this=0x9062860, th=0x9072fc0) at ../application/workerthreadtask.cpp:39 #14 0x0804fe50 in Thread::start(void*) (data=0x9072fc0) at ../util/thread.cpp:122 #15 0x0097b79c in start_thread () from /lib/tls/libpthread.so.0 #16 0x007c827a in clone () from /lib/tls/libc.so.6