• Welcome to Valhalla Legends Archive.
 

compile warnings, conversion problems

Started by warz, May 20, 2006, 03:07 AM

Previous topic - Next topic

warz

now, its not good practice to just ignore compiler warnings, especially when they're something along the lines of..


g C4312: 'type cast' : conversion from 'DWORD' to 'LPVOID' of greater size
c:\Documents and Settings\...\bwlib\PatchClass.cpp(24) : warning C4312: 'type cast' : conversion from 'DWORD' to 'BYTE *' of greater size
c:\Documents and Settings\...\bwlib\PatchClass.cpp(25) : warning C4312: 'type cast' : conversion from 'DWORD' to 'DWORD *' of greater size
c:\Documents and Settings\...\bwlib\PatchClass.cpp(28) : warning C4312: 'type cast' : conversion from 'unsigned long' to 'BYTE *' of greater size
c:\Documents and Settings\...\bwlib\PatchClass.cpp(30) : warning C4312: 'type cast' : conversion from 'DWORD' to 'LPVOID' of greater size


Now, i did this because it was just what 'worked' at the moment. I'm going back through and redoing functions that I flagged as 'horrible' while making them. What method would more acceptable, and hopefully not generate all these warnings? Here's the lines that are causing these warnings. They should be pretty obvious as to which warning goes with which line.. aside from the fact that theyre all in corresponding order...


VirtualProtect((LPVOID)AddressToPatch, 5 + PadSize, PAGE_EXECUTE_READWRITE, &OldProtect);
*(BYTE*)AddressToPatch = CallOperand;
*(DWORD*)(AddressToPatch + 1) = DataBuffer;
*(BYTE*)(AddressToPatch+5+x) = 0x90;
VirtualProtect((LPVOID)AddressToPatch, 5 + PadSize, OldProtect, &OldProtect);


AddressToPatch is of type DWORD.
CallOperand is of type BYTE.
DataBuffer is of type DWORD.

I have a feeling kp will respond with something in relation to those uint_8 or whatever types are? That's what I'm hoping atleast.

Kp

All the warnings stem from using a 32bit integer in place of a pointer.  This works on Win32, since pointers are 32bits also.  It will break on Win64, hence the compiler warnings.  The easiest fix would be to make AddressToPatch a void* instead of a DWORD.  However, IIRC, MSVC does not take well to doing arithmetic on void pointers.  You could make it a uint8_t *, BYTE *, or any other pointer to an 8bit data type.  Your other option would be to make AddressToPatch a DWORD_PTR, which is a horribly silly name that Microsoft came up with to mean "unsigned long integer big enough to be used as a pointer on the current architecture."  It's never actually a double word, but its size will be correct for what you want.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Maddox

  ;)

#pragma warning(disable : 4311 312)
asdf.

Kp

Warnings should only be turned off when fixing the code is difficult, i.e. bogus warnings about unreachable code.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!