Showing posts with label sigsegv. Show all posts
Showing posts with label sigsegv. Show all posts

Saturday, January 24, 2009

SIGSEGV on statement with std::string variable, G++.

If you have error report like

Program received signal SIGSEGV, Segmentation fault.
0xb7d2be69 in __gnu_cxx::__exchange_and_add () from /usr/lib/libstdc++.so.6
(gdb) where
#0 0xb7d2be69 in __gnu_cxx::__exchange_and_add () from /usr/lib/libstdc++.so.6
#1 0xb7d0dfcc in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string () from /usr/lib/libstdc++.so.6
...

or

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb746b6d0 (LWP 9469)]
0xb7c5ce69 in __gnu_cxx::__exchange_and_add () from /usr/lib/libstdc++.so.6
(gdb) where
#0 0xb7c5ce69 in __gnu_cxx::__exchange_and_add () from /usr/lib/libstdc++.so.6
#1 0xb7c3e8e4 in std::string::assign () from /usr/lib/libstdc++.so.6
#2 0xb7c3e944 in std::string::operator= () from /usr/lib/libstdc++.so.6
...

or something similar,
check that memory under string variable isn't corrupted.
In my case the problem was with zeroed memory. In Visual Studio I used the ugly but effective construction like

string a;
memset(&a, 0, sizeof(a));

and I didn't have problems with it. But in g++ and in general I must be more accurate.