[ACCEPTED]-C++ Program Always Crashes While doing a std::string assign-stdstring

Accepted answer
Score: 10

This is an initial guess using all information 6 I can extract from your back trace.

You are 5 most likely mixing and matching gcc version, linker 4 and libstdc++ that results an unusual behaviour 3 on the host machine:

  1. libc is the system's: /lib64/libc.so.6
  2. libstdc++ is in a "ThirdParty" directory - this is suspicions, as it tells me it might be compiled elsewhere with a different target - /home/bbazso/ThirdParty/sources/gcc-4.2.4/x86_64-pc-linux-gnu/libstdc++-v3/
  3. Yet another libstdc++ in /opt: /opt/trx-HEAD/gcc/4.2.4/lib/gcc/x86_64-pc-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/basic_string.h:491

In addition, GCC may 2 mix the system's ld instead of itself which 1 may cause further weird memory maps usage.

Score: 7

Can you repeat the crash with a basic two 7 line program?

#include <string>

int main()
{
    std::string abc;
    abc = "testString";
}

If that crashes, please post 6 your exact compile / link options?

If not, start 5 paring down your code. Remove things lines 4 a handful at a time until the bug goes away. Once 3 you have some other change you can add to cause 2 the crash and remove to make it go away, that 1 should help you locate the problem.

Score: 2

Happened to me because of using malloc for 1 a class which had std::strings as data members. Tricky.

Score: 0

As you said it's a weird behavior.

To be 12 honnest with i think you are wasting time 11 looking into a possible bug with std::strings. Strings 10 are perfectly safe as long as you are using 9 them well.

Anyway, with the informations 8 you are giving : First, are you using threads 7 ? It's might be a thread problem. Second, you 6 check your program using valgrind. Have 5 you no warnings at all ?

Note : The most 4 critical valgrind's warnings are invalid 3 read and invalid write.

PS : As said in commentary, you 2 should probably use g++ to compile C++ code 1 ;)

More Related questions