Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. a non understandable debug error!

a non understandable debug error!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondebugging
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gerald Mercet
    wrote on last edited by
    #1

    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

    J N 2 Replies Last reply
    0
    • G Gerald Mercet

      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

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • G Gerald Mercet

        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

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          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

          G Offline
          G Offline
          Gerald Mercet
          wrote on last edited by
          #4

          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

          J F 2 Replies Last reply
          0
          • G Gerald Mercet

            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

            J Offline
            J Offline
            Joaquin M Lopez Munoz
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • G Gerald Mercet

              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

              F Offline
              F Offline
              Felix Cho
              wrote on last edited by
              #6

              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.

              G 2 Replies Last reply
              0
              • F Felix Cho

                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.

                G Offline
                G Offline
                Gerald Mercet
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • F Felix Cho

                  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.

                  G Offline
                  G Offline
                  Gerald Mercet
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups