Author | Message | Time |
---|---|---|
warz | now, its not good practice to just ignore compiler warnings, especially when they're something along the lines of.. [code] 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 [/code] 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... [code] 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); [/code] 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. | May 20, 2006, 8:07 AM |
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. | May 20, 2006, 5:39 PM |
Maddox | ;) [code]#pragma warning(disable : 4311 312)[/code] | June 5, 2006, 10:05 AM |
Kp | Warnings should only be turned off when fixing the code is difficult, i.e. bogus warnings about unreachable code. | June 5, 2006, 11:14 PM |