Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ string
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":
 
        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 9-Apr-13 6:45am
Comments
   
I find no syntax error. can you give more details?
Richard MacCutchan at 9-Apr-13 13:14pm
   
I just ran this code with no problem; which line does the error occur on?
nv3 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
patrik polakovic at 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 at 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)

  Print Answers RSS
0 OriginalGriff 605
1 Maciej Los 319
2 BillWoodruff 184
3 Richard MacCutchan 180
4 Suraj Sahoo | Coding Passion 180
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100