• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[Help] Converting 2k3 to 2k8 source

jow

Junior Spellweaver
Joined
Nov 30, 2009
Messages
111
Reaction score
132
Hi can anyone help me converting this part of source its a deprecated code in my source "std::copy"

can i ask what is your code for this??

Code:
inline BOOL CByteStream::operator >> ( DWORD &Value )
{
	int sizeBuff = (int)(m_Buffer.end() - (m_Buffer.begin()+m_dwIter));
	GASSERT ( sizeof(Value)<=sizeBuff );

	std::copy ( &m_Buffer[m_dwIter], &m_Buffer[m_dwIter+sizeof(Value)], LPBYTE(&Value) );

	m_dwIter += sizeof(Value);

	return TRUE;
}

edit:
someone advice me to use memcpy for std::copy.. the source and all library are all updated to vs2008 and games run but, some part of the game makes crash and i tried to debug it and it points to this part of source.
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
Actually quite a lot of things can go wrong here.
You only showed a small snippet of code which depends on the "CByteStream" class so I'm not totally sure what the instance variables are used for.
I'm also confused about the topic of a code upgrading issue while you seem to have a problem with code stability.

Also is m_Buffer a vector or some kind of custom Buffer class?

More information is needed to help you on the topic, but most likely you run into a buffer overflow at some point as I can't see any kind of validation of "m_dwIter" here. (GASSERT with other assertion methods tend to work in DEBUG mode only)

Btw. Your question is wrongly tagged with [C] as this is [C++] code.
 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
Isn't that assert a bit pointless? I mean as far as I know sizeof operator is an unsigned type so compiler will convert sizeBuff to unsigned while making the comparison. So if your sizeBuff is < 0 it'll ignore the assert and keep executing. You could try casting the return value of sizeof to int in assert.
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
Isn't that assert a bit pointless? I mean as far as I know sizeof operator is an unsigned type so compiler will convert sizeBuff to unsigned while making the comparison. So if your sizeBuff is < 0 it'll ignore the assert and keep executing. You could try casting the return value of sizeof to int in assert.

Looks like he's trying to make sure the value being pushed into the stream doesn't exceed it's size. But as that one is completely ignoring m_dwIter that is used as index it's completely useless.
Also, as said, the ASSERT will probably only fire in debug mode.
 
Back
Top