I have the following function MyType::Is_Inst ()that throws an invalid memory access error when returning in 64-bit mode, but not in 32-bit mode:
MyType MyType::Is_Inst () {
unsigned char Bar=0;
MyType Foo={0};
return Foo;
}
Looking at the dismantle + step, the program crashes in a line
mov dword ptr [rax],ecx
... when the program basically tries to dereference the original value of% rdx (since the function was called), which is now in% rax. However,% rdx is simply inactive from the previous function call.
The last time I had such a problem, it was because I was missing from some compilation flags, etc. Should there be any settings for x64 unmanaged C ++ projects? Are there other reasons why I can see this behavior?
I can post more showdown if you need it.
MyType :
class __declspec(dllexport) MyType {
public:
union {
struct {
unsigned int Id : 23;
unsigned int Flag : 1;
unsigned int Type : 4;
unsigned int Unused : 4;
};
unsigned int All_Bits;
};
};
UPDATE: , Is_Inst(), . , .
mov dword ptr [rdx],0
mov rax,rdx
ret
, Is_Inst():
...
for (Counter=0; Counter<N_Items; Counter++) {
...
myOther32BitType = arrayOfMyOtherTypes [Counter];
if (myOther32BitType.8BitField==UNEQUAL_ENUM_VALUE) {
}
else if (strchr((char*)Uchar_Table_Of_Enum_Values, myOther32BitType.8BitField)) continue;
else if (strchr((char*)Other_Uchar_Table_Of_Enum_Values, myOther32BitType.8BitField)) continue;
else if ( myOther32BitType.8BitField==EQUAL_ENUM_VALUE) {
if (myType.Is_Inst ().All_Bits) {
return false;
}
...
}
...
}