Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i have a problem with assigning string to string field in my structure. Here is structure:
struct CIMUNTYPEDFRAMEWORK_API ConnectionInfo {
    AuthMethod authmethod;
    string certificate;
    bool local;
    string oid;
    string host;
    int port;

    string username;
    string password;

    string proxy_host;
    string proxy_user;
    string proxy_password;
    bool secure;

    ConnectionInfo();
    ~ConnectionInfo();
};


And here is piece of code causing the "problem":

C++
    ConnectionInfo connection;

connection.authmethod = DIGEST;
connection.host.assign("...");
connection.port = 0;
connection.username.assign("...");
connection.password.assign("...");
connection.secure = false;
connection.certificate.assign("");
connection.local = false;
connection.oid.assign("");
connection.proxy_host.assign("");
connection.proxy_user.assign("");
connection.proxy_password.assign("");


After stepping over in debugger throught any of string assignments, i have got an error:
Unhandled exception at 0x002a42a8 in AccessMonitor.exe: 0xC0000005: Access violation writing location 0x002f2885.


Thank you for answers.
Posted
Comments
José Amílcar Casimiro 9-Apr-13 12:16pm    
I find no syntax error. can you give more details?
Richard MacCutchan 9-Apr-13 13:14pm    
I just ran this code with no problem; which line does the error occur on?
nv3 9-Apr-13 16:34pm    
That somehow looks to me like the constructor of those std::string members is not being executed. Then the assign operation will try to replace an existing string with something and thereby tries to manipulate an uninitialized string.

Could it be that your original code contains a different initialization that just
ConnectionInfo connection;

For example, if you'd try to do something like
ConnectionInfo* pCI = malloc (sizeof ConnectionInfo);

and then work with that pointer, things would go definitely go south.

1 solution

My immediate thought is that there is some conflict between the string types in the implementation of ConnectionInfo and your piece of problem code.

I shall presume they are both std::string. If the ConnectionInfo implementation is provided as a binary (either static or dynamically linked) there may be a conflict with compiler settings or std lib implementations used when building your code.

If this is the case, then the error really lies with the provider of the library, as it is generally a bad idea to put anything but fundamental types on a library interface, as the stl standard does not stipulate binary compatibility between implementations[^].

Sadly, even debug and release versions of the same implementation can cause problems on library interfaces.
 
Share this answer
 
Comments
patrik polakovic 10-Apr-13 3:46am    
Sorry i did not mention that this code is from Intel AMT KIT. I have tried to build one of the sample but with following error:
1>LINK : fatal error C1047: The object or library file '..\..\..\..\..\Lib\CimOpenWsmanClient.lib' was created with an older compiler than other objects; rebuild old objects and libraries

I've rebuilt it (also other needed components) and from this moment I have this problem with assignment. Any solutions?
H.Brydon 12-Apr-13 14:39pm    
Your only choices are (1) to use the compiler they built the library from (and the same debug/release build) or (2) somehow recompile their library from source using whatever compiler version (and settings) that you are developing your code with.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900