Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a strange debur error

Status
Not open for further replies.

jayjay60

Programmer
Jun 19, 2001
97
FR
I have created a dialog app, which return a debug error meesage that i don't understand. This message is:
Debug error

Program:D:\CalcRiskPort\Debug\CalcRiskPort.exe
DAMAGE: after Normal block (#81) at 0x00301190

when i pree retry i have this message box:

User breakpoint called from code at 0x1021376f

you could see the following code concerned

void CCalcRiskPortDlg::OnCalcvar()
{
UpdateData(TRUE);
::CoInitialize(NULL);

//LoadTables Table;
//LoadTables Table2(m_dlgSector);
double *pTabVar=new double[(double)pow(2,m_dlgAsset)];
double *pTabMoy=new double[(double)pow(2,m_dlgAsset)];

CString *pTabPortStr=new CString[(long)pow(2,m_dlgAsset)];
CString strValue,strPortOpti,strMaxiSharpe,strMaxiEfficience;
double MiniVar,MaxiSharpe,MaxiEfficience;
int Rang;
double *pMiniVar=new double[2];
//double *pMiniRatio=new double[2];
double *pMaxiRatioSharpe=new double[2];
double *pMaxiRatioEfficience=new double[2];

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&CorrelDB.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é");
Table.pYield=Table.LoadYield(m_dlgSector,Table.pYield,"Ratio");

i=0;

for(k=0;k<=m_dlgAsset-1;k++)
{
*(pTabBinPort+k)=0;

Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort);
}
*pTabVar=Table.CalcVar(pTabNumPort,m_dlgAsset);
*pTabMoy=Table.CalcMoy(pTabNumPort,m_dlgAsset);
Table.pRatioSharpe[0]=(*pTabMoy)/(*pTabVar);
Table.pRatioEfficience[0]=((*pTabMoy+i)-m_dlgRate0)/(*pTabVar);
*pTabPortStr=Table.AgregIntToStr(pTabNumPort,m_dlgAsset);

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);
*(pTabMoy+i)=Table.CalcMoy(pTabNumPort,m_dlgAsset);
Table.pRatioEfficience=(*(pTabMoy+i))/(*(pTabVar+i));
Table.pRatioSharpe=((*(pTabMoy+i))-m_dlgRate0)/(*(pTabVar+i));
*(pTabPortStr+i)=Table.AgregIntToStr(pTabNumPort,m_dlgAsset);

}
pMiniVar=Table.CalcMin(pTabVar,pMiniVar,(long)pow(2,m_dlgAsset));
pMaxiRatioSharpe=Table.CalcMax(Table.pRatioSharpe,pMaxiRatioSharpe,m_dlgAsset);
pMaxiRatioEfficience=Table.CalcMax(Table.pRatioEfficience,pMaxiRatioEfficience,m_dlgAsset);
MiniVar=pMiniVar[0];
MaxiSharpe=pMaxiRatioSharpe[0];
MaxiEfficience=pMaxiRatioEfficience[0];
Rang=(int)pMiniVar[1];

m_dlgValue=pTabVar[Rang];
m_dlgValue *=100;
m_dlgPortOpti=*(pTabPortStr+Rang);
strPortOpti=m_dlgPortOpti;
m_dlgSharpe=MaxiSharpe;
m_dlgEfficience=MaxiEfficience;
strMaxiSharpe.Format(&quot;%.5f&quot;,m_dlgSharpe);
strMaxiEfficience.Format(&quot;%.5f&quot;,m_dlgEfficience);

strValue.Format(&quot;%.5f&quot;,m_dlgValue);
CEdit* PEdit=(CEdit*)GetDlgItem(IDC_VALUE);
PEdit->SetWindowText(strValue);
CEdit* SEdit=(CEdit*)GetDlgItem(IDC_OPTI_PORT);
SEdit->SetWindowText(strPortOpti);
CEdit* ShEdit=(CEdit*)GetDlgItem(IDC_OPTI_SHARPE);
ShEdit->SetWindowText(strMaxiSharpe);
CEdit* EffEdit=(CEdit*)GetDlgItem(IDC_OPTI_EFFICIENCE);
EffEdit->SetWindowText(strMaxiEfficience);
delete []pMiniVar;
delete []pMaxiRatioSharpe;
delete []pMaxiRatioEfficience;
delete []pTabBinPort;
delete []pTabNumPort;
delete []pTabVar;
delete []pTabMoy;

pConnection->Close();

}
catch(_com_error &e)
{
AfxMessageBox(&quot;a pas bon&quot;);
}

::CoUninitialize();

// TODO: Add your control notification handler code here

}

so i hope that someone could help me to solve my problem

thanks in advance for your answers

jayjay
 
The debug version of new allocates a few more bytes of extra memory before and after the block of memory that you requested, and initialized it with some fixed patterns.

When you call delete, the debug version of delete checks these pre- and post-block of memory for the patterns it initialized. If they are modified, that means your code is writing beyond the allocated area.

Put a breakpoint on the first delete and single step from there on. Look at the output window when you single step. The line that causes the error is the memory that get out-of bound write. Check the code that write to the memory.

HTH
Shyan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top