ChatCloud
ChatCloud

Reputation: 1200

std::string is totally crashing in msvcp90d.dll

The library is using std::string. When some specific application is linked with it, the string operations performed in library are getting totally crashy.

For instance the string assignment operator '=' (stack trace is attached).

enter image description here

The destination of memcpy_s( ... ) and size are looking quite scrambled.

We can not repro it locally. Please advice.

Edit: code is looking like this:

...
#define DEFAULT_VAL "value"
...
class MyClass {
public:
 MyClass(const std::string& s=DEFAULT_VAL)
 {
  _test() = s;
 }
protected:
 inline const std::string& test() const {return m_test;}
 inline std::string& _test() {return m_test;}
private:
 std::string m_test;
};

....
MyClass c;

Upvotes: 1

Views: 371

Answers (2)

Mr.C64
Mr.C64

Reputation: 43014

If you are in a case of a DLL exposing std::string at the interface, make sure that both the .EXE and the .DLL are built with the same compiler version and the same flavor of the CRT (e.g. both debug, both release, both with the same settings of _HAS_ITERATOR_DEBUGGING, etc.).

Upvotes: 2

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145429

You are probably initializing a std::string (or std::wstring) with 0, most likely via a nullpointer, like…

#include <string>
using namespace std;

int main()
{
    string s1( 0 );
    string s2 = s1;
}

Don’t do that.

There aren’t many other ways to make std::string “crashy”, so chances are that this is it. Now go debugging! Good luck!

Upvotes: 4

Related Questions