Re: 关于空指针访问错误

WinDbg

关于空指针访问错误


tonyYe 2012-07-16, 13:00 下午
我用下面的测试代码。
class a
{
public:
void Test(){ s+= 3;}
int s;
int t;
};

void HHH(int s,int t,int i)
{
a *p = new a;
delete p;
p = NULL;
p->Test();
}

这个程序运行的时候在p->Test崩溃。用windbg分析下,它提示的exception是
EXCEPTION_RECORD:  0012f3c0 -- (.exr 0x12f3c0)
ExceptionAddress: 0040151f (EccomVdsTes!HHH+0x0000000f)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000001
   Parameter[1]: 00000000
Attempt to write to address 00000000
为什么显示这个参数(NumberParameters: 2)有两个啊?

Re: 关于空指针访问错误


格蠹老雷 2012-07-17, 12:37 下午
在EXCEPTION_RECORD Structure的SDK文档中解释的很清楚:   NumberParameters

The number of parameters associated with the exception. This is the number of defined elements in the ExceptionInformation array.

ExceptionInformation

An array of additional arguments that describe the exception. The RaiseException function can specify this array of arguments. For most exception codes, the array elements are undefined. The following table describes the exception codes whose array elements are defined.

Exception code Meaning
EXCEPTION_ACCESS_VIOLATION

The first element of the array contains a read-write flag that indicates the type of operation that caused the access violation. If this value is zero, the thread attempted to read the inaccessible data. If this value is 1, the thread attempted to write to an inaccessible address. If this value is 8, the thread causes a user-mode data execution prevention (DEP) violation.

The second array element specifies the virtual address of the inaccessible data.

EXCEPTION_IN_PAGE_ERROR

The first element of the array contains a read-write flag that indicates the type of operation that caused the access violation. If this value is zero, the thread attempted to read the inaccessible data. If this value is 1, the thread attempted to write to an inaccessible address. If this value is 8, the thread causes a user-mode data execution prevention (DEP) violation.

The second array element specifies the virtual address of the inaccessible data.

The third array element specifies the underlying NTSTATUS code that resulted in the exception.

Powered by Community Server Powered by CnForums.Net