C ++在获取指针时崩溃

时间:2013-05-19 16:36:53

标签: c++

我猜它无处可去,一个空指针或其他东西,但我事先正在检查

这两个片段都崩溃了:

//Snippet 1
DWORD *address = (DWORD*)(base + 0x54);

if (address)
    address = (DWORD*)(*address + 0xC);

if (address)
    address = (DWORD*)(*address + 0x8);   //crashes here


//Snippet 2
DWORD address = *(DWORD*)(base + 0x54);

if (address)
    address = *(DWORD*)(address + 0xC);

if (address)
    address = *(DWORD*)(address + 0x8);   //crashes here

我做错了吗? 提前致谢

1 个答案:

答案 0 :(得分:1)

访问违规!

你正在触摸可能禁止你的程序的某些内存部分。取消引用指向未知位置的指针是未定义的行为。