Hi,

I get the following Valgrind / GDB output when I run my code. This cod e works on some Linux machine and on some others in gives a seg fault with this output. Pasting my code is not a good option since there is a lot of it and the violating line provides not hints. Does this look familiar to anyone?

==12458== 1 errors in context 1 of 2:
==12458== Invalid read of size 4
==12458==    at 0x687A561: std::string::size() const (basic_string.h:596)
==12458==    by 0x687D21B: std::string::assign(char const*, unsigned) (basic_string.tcc:267)
==12458==    by 0x80C1D52: main (main.cpp:19)
==12458==  Address 0xfffffff5 is not stack'd, malloc'd or (recently) free'd
==12458== 
==12458== 1 errors in context 2 of 2:
==12458== Use of uninitialised value of size 4
==12458==    at 0x687A561: std::string::size() const (basic_string.h:596)
==12458==    by 0x687D21B: std::string::assign(char const*, unsigned) (basic_string.tcc:267)
==12458==    by 0x80C1D52: main (main.cpp:19)

Recommended Answers

Your program has probably trashed memory somewhere. I'm 99.999% certain the problem is NOT witth std::string so it must be somewhere else. Look for buffer overruns and use of initialized pointers or dereferencing null pointers.

If you can please attach the files instead of just posting them with code …

Jump to Post

All 3 Replies

Your program has probably trashed memory somewhere. I'm 99.999% certain the problem is NOT witth std::string so it must be somewhere else. Look for buffer overruns and use of initialized pointers or dereferencing null pointers.

If you can please attach the files instead of just posting them with code tags. You can tar them (or zip them) without object files to make the tar file smaller.

What is the value of arguments of std::string::assign ?

I had a problem with std::strings in STLport version 4.6... they thrashed my stack
when calling a constructor like

Object(std::string name, Object *parent)

new Object("something", NULL)

As I passed NULL as parent, it appeared as some random pointer...which obviously crashed the program.

Then, I installed STLport 5.1 (the last stable version as for 9/jul/2008), and the problems are now gone.


Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.