C++中debug error如何解决?

来源:百度知道 编辑:UC知道 时间:2024/09/20 21:34:35
源代码:
BigInt synSign(BigInt &bi)
{ BigInt result;
int k=bi.m_nN;
if(bi.m_pNum[bi.m_nN-1]>0)
{
for(int i=0;i<bi.m_nN-1;i++)
{
if(bi.m_pNum[i]<0)
{
bi.m_pNum[i]=bi.m_nRadix+bi.m_pNum[i];
bi.m_pNum[i+1]-=1;
}
}
}
else
{
for(int j=0;j<bi.m_nN-1;j++)
{
if(bi.m_pNum[j]>0)
{
bi.m_pNum[j]-=bi.m_nRadix;
bi.m_pNum[j+1]+=1;
}
}
}

while(bi.m_pNum[k-1]==0)
k--;
bi.m_nN=k;

result.m_nN=bi.m_nN;
result.m_nCapacity=bi.m_nCapacity;
result.m_pNum=new int[result.m_nCapacity];

for(int l=0;l<result.m_nN;l++)
result.m_pNum[l]=bi.m_pNum[l];

return result;

}
一调试就有:heap corruption detected;
after normal block(#152)at Ox003b8a08
crt detected that the application wrote to memory afte

the application wrote to memory after end buffer

写的这么清楚了:应用程序向数组后的内存进行了写操作。
数组越界

一般是数组越界吧,你仔细检查下程序中用到new,delete的地方