a non understandable debug error!
-
In my application i have a debug error message that occurs when i want to delete a pointer. in the code: int *pTabBinPort=new int[m_dlgAsset]; . . . . delete []pTabBinPort; i do that at the end of a function, and when i do debug test when it arrives to this point a message error box arrives and i could read this message: Debug error! Program : D:\CalcRiskPort\Debug\CalcRiskPort.exe DAMAGE : before Normal block(#74) at 0x00301E20 So, is anybody could explain to me what is the problem? Thanks in advance for your answers gerald
-
In my application i have a debug error message that occurs when i want to delete a pointer. in the code: int *pTabBinPort=new int[m_dlgAsset]; . . . . delete []pTabBinPort; i do that at the end of a function, and when i do debug test when it arrives to this point a message error box arrives and i could read this message: Debug error! Program : D:\CalcRiskPort\Debug\CalcRiskPort.exe DAMAGE : before Normal block(#74) at 0x00301E20 So, is anybody could explain to me what is the problem? Thanks in advance for your answers gerald
The error means memory got corrupted for some reason. First thing I'd check is whether you're not running out of bounds when writing to
pTabBinPort
. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
In my application i have a debug error message that occurs when i want to delete a pointer. in the code: int *pTabBinPort=new int[m_dlgAsset]; . . . . delete []pTabBinPort; i do that at the end of a function, and when i do debug test when it arrives to this point a message error box arrives and i could read this message: Debug error! Program : D:\CalcRiskPort\Debug\CalcRiskPort.exe DAMAGE : before Normal block(#74) at 0x00301E20 So, is anybody could explain to me what is the problem? Thanks in advance for your answers gerald
You are not changing pTabBinPort anywhere are you? If you want to do some pointer arithmetic do it on a tmp pointer variable. Or it could be that you are overflowing the allocated memory Nish It's seven o'clock On the dot I'm in my drop top Cruisin' the streets - Oh yeah I got a real pretty, pretty little thing that's waiting for me
-
The error means memory got corrupted for some reason. First thing I'd check is whether you're not running out of bounds when writing to
pTabBinPort
. Joaquín M López Muñoz Telefónica, Investigación y Desarrolloi don't know if it could help you but i post the entire code of my function: void CCalcRiskPortDlg::OnCalcvar() { UpdateData(TRUE); ::CoInitialize(NULL); //LoadTables Table; //LoadTables Table2(m_dlgSector); double *pTabVar=new double[pow(2,m_dlgAsset)]; CString strValue; int *pTabBinPort=new int[m_dlgAsset]; int *pTabNumPort=new int[m_dlgAsset]; int k,i; try { LoadTables Table(1,m_dlgSector,1,m_dlgSector); _ConnectionPtr pConnection=NULL; CString strTemp; strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\CalcRiskPort\\vol_correl1.mdb;"); _bstr_t strCnn(strTemp); TESTHR(pConnection.CreateInstance(__uuidof(Connection))); pConnection->Open(strCnn,"","",adConnectUnspecified); Table.pCorrel=Table.LoadCorrelation(m_dlgSector,Table.pCorrel,"Correlation"); Table.pVol=Table.LoadVolatility(m_dlgSector,Table.pVol,"Volatilité"); i=0; for(k=0;k<=m_dlgAsset-1;k++) { *(pTabBinPort+k)=0; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); } *pTabVar=Table.CalcVar(pTabNumPort,m_dlgAsset); for(i=1;i<=pow(2,m_dlgAsset);i++) { k=m_dlgAsset-1; while(*(pTabBinPort+k)==1) { *(pTabBinPort+k)=0; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); k--; } *(pTabBinPort+k)=1; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); *(pTabVar+i)=Table.CalcVar(pTabNumPort,m_dlgAsset); } pConnection->Close(); } catch(_com_error &e) { AfxMessageBox("a pas bon"); } m_dlgValue=pTabVar[2]; strValue.Format("%.9f",m_dlgValue); CEdit* PEdit=(CEdit*)GetDlgItem(IDC_VALUE); PEdit->SetWindowText(strValue); delete []pTabBinPort; delete []pTabNumPort; delete []pTabVar; ::CoUninitialize(); // TODO: Add your control notification handler code here } i hope it help you regards
-
i don't know if it could help you but i post the entire code of my function: void CCalcRiskPortDlg::OnCalcvar() { UpdateData(TRUE); ::CoInitialize(NULL); //LoadTables Table; //LoadTables Table2(m_dlgSector); double *pTabVar=new double[pow(2,m_dlgAsset)]; CString strValue; int *pTabBinPort=new int[m_dlgAsset]; int *pTabNumPort=new int[m_dlgAsset]; int k,i; try { LoadTables Table(1,m_dlgSector,1,m_dlgSector); _ConnectionPtr pConnection=NULL; CString strTemp; strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\CalcRiskPort\\vol_correl1.mdb;"); _bstr_t strCnn(strTemp); TESTHR(pConnection.CreateInstance(__uuidof(Connection))); pConnection->Open(strCnn,"","",adConnectUnspecified); Table.pCorrel=Table.LoadCorrelation(m_dlgSector,Table.pCorrel,"Correlation"); Table.pVol=Table.LoadVolatility(m_dlgSector,Table.pVol,"Volatilité"); i=0; for(k=0;k<=m_dlgAsset-1;k++) { *(pTabBinPort+k)=0; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); } *pTabVar=Table.CalcVar(pTabNumPort,m_dlgAsset); for(i=1;i<=pow(2,m_dlgAsset);i++) { k=m_dlgAsset-1; while(*(pTabBinPort+k)==1) { *(pTabBinPort+k)=0; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); k--; } *(pTabBinPort+k)=1; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); *(pTabVar+i)=Table.CalcVar(pTabNumPort,m_dlgAsset); } pConnection->Close(); } catch(_com_error &e) { AfxMessageBox("a pas bon"); } m_dlgValue=pTabVar[2]; strValue.Format("%.9f",m_dlgValue); CEdit* PEdit=(CEdit*)GetDlgItem(IDC_VALUE); PEdit->SetWindowText(strValue); delete []pTabBinPort; delete []pTabNumPort; delete []pTabVar; ::CoUninitialize(); // TODO: Add your control notification handler code here } i hope it help you regards
It's hard to say... This is a little suspicious:
for(i=1;i<=pow(2,m_dlgAsset);i++)
{
...
*(pTabVar+i)=Table.CalcVar(pTabNumPort,m_dlgAsset);
}i
runs between 1 and 2m_dlgAsset
, and then you use it as an index to pTabVar. I think you should change the last sentence to*(pTabVar+i-1)=...;
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
i don't know if it could help you but i post the entire code of my function: void CCalcRiskPortDlg::OnCalcvar() { UpdateData(TRUE); ::CoInitialize(NULL); //LoadTables Table; //LoadTables Table2(m_dlgSector); double *pTabVar=new double[pow(2,m_dlgAsset)]; CString strValue; int *pTabBinPort=new int[m_dlgAsset]; int *pTabNumPort=new int[m_dlgAsset]; int k,i; try { LoadTables Table(1,m_dlgSector,1,m_dlgSector); _ConnectionPtr pConnection=NULL; CString strTemp; strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\CalcRiskPort\\vol_correl1.mdb;"); _bstr_t strCnn(strTemp); TESTHR(pConnection.CreateInstance(__uuidof(Connection))); pConnection->Open(strCnn,"","",adConnectUnspecified); Table.pCorrel=Table.LoadCorrelation(m_dlgSector,Table.pCorrel,"Correlation"); Table.pVol=Table.LoadVolatility(m_dlgSector,Table.pVol,"Volatilité"); i=0; for(k=0;k<=m_dlgAsset-1;k++) { *(pTabBinPort+k)=0; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); } *pTabVar=Table.CalcVar(pTabNumPort,m_dlgAsset); for(i=1;i<=pow(2,m_dlgAsset);i++) { k=m_dlgAsset-1; while(*(pTabBinPort+k)==1) { *(pTabBinPort+k)=0; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); k--; } *(pTabBinPort+k)=1; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); *(pTabVar+i)=Table.CalcVar(pTabNumPort,m_dlgAsset); } pConnection->Close(); } catch(_com_error &e) { AfxMessageBox("a pas bon"); } m_dlgValue=pTabVar[2]; strValue.Format("%.9f",m_dlgValue); CEdit* PEdit=(CEdit*)GetDlgItem(IDC_VALUE); PEdit->SetWindowText(strValue); delete []pTabBinPort; delete []pTabNumPort; delete []pTabVar; ::CoUninitialize(); // TODO: Add your control notification handler code here } i hope it help you regards
This looks suspicious as well:
while(*(pTabBinPort+k)==1)
{
*(pTabBinPort+k)=0;
Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort);
k--;
}Could there be any chance that k is <0 and you step out of bounds? Putting an assert on k after decrement or (better yet?)
VERIFY(--k >= 0)
should help detect this problem in debug mode. -
This looks suspicious as well:
while(*(pTabBinPort+k)==1)
{
*(pTabBinPort+k)=0;
Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort);
k--;
}Could there be any chance that k is <0 and you step out of bounds? Putting an assert on k after decrement or (better yet?)
VERIFY(--k >= 0)
should help detect this problem in debug mode.i've just read your post and i think that it's exactly the problem, because, when i arrive to pTabBinPort[0], i decrement again k so that it will be equal to -1. So, i will test it to see if it works; thanks a lot
-
This looks suspicious as well:
while(*(pTabBinPort+k)==1)
{
*(pTabBinPort+k)=0;
Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort);
k--;
}Could there be any chance that k is <0 and you step out of bounds? Putting an assert on k after decrement or (better yet?)
VERIFY(--k >= 0)
should help detect this problem in debug mode.in fact in my code i change 2 things: for(i=1;i<=pow(2,m_dlgAsset)-1;i++) { k=m_dlgAsset-1; while(*(pTabBinPort+k)==1) { *(pTabBinPort+k)=0; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); if(k!=0) k--; } *(pTabBinPort+k)=1; Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort); *(pTabVar+i)=Table.CalcVar(pTabNumPort,m_dlgAsset); } you could see in the for statement that i going from 1 to pow(2,m_dlgAsset)-1 now and i've put a test in the while loop just for the case of k=0, so that we couldn't be in the situation of k=-1. But now i have another problem, when i test my application with m_dlgSector=30 and m_dlgAsset=15, at the end of the function i have another message error which says: Unhandled exception in CalcRiskport.exe (MFC42.DLL):0xC0000005:Access Violation. It's happened at this line: strValue.Format("%.5f",m_dlgValue); You could see the whole code in the precedent post.