■求救■:内存操作错误的判断解析(急啊)

beacholi 2008-02-22 10:16:23
各位大侠,拜托看看一面这段代码,其中对difNo 的操作哪个地方违法了,
会造成系统崩溃。。。
当然,上面是我自己的判断,不一定正确。
(因为在84行,我去delete difNo,发现运行到这里时候出错了)
拜托了~
(昨天被老大逼了一夜也没有搞定,哭啊)

补充:

这个函数外面还有一个文件的循环,调用这个函数

—————————————————————————————————————————————————————————————————————————————————————————
1 int * difNo = new int(); //■■■■■
2
3 int difCnt = 0;
4
5 for(int cnt = 0; cnt < (int)m_pSrcCdrArray->GetCount(); cnt++)
6 {
7 pSrcCdrField_t = ( g_pCdrField_t )m_pSrcCdrArray->GetAt(cnt);
8
9 // find the same field in the destination CDR array
10 index = getValue(pSrcCdrField_t->strHeader, &strValue, m_pDesCdrArray);
11
12 if(index == -1)
13 {
14 diffArray.Add(_T("<") + pSrcCdrField_t->strLine + _T("\n\n"));
15 difNo[difCnt++] = -1; //■■■■■
16 } //if(index == -1)
17 else if(strValue != pSrcCdrField_t->strValue)
18 {
19 pDesCdrField_t = ( g_pCdrField_t ) m_pDesCdrArray->GetAt(index);
20 diffArray.Add(_T("<") + pSrcCdrField_t->strLine + _T("\n"));
21 diffArray.Add(_T(">") + pDesCdrField_t->strLine + _T("\n\n"));
22 m_pDesCdrArray->RemoveAt(index);
23 difNo[difCnt++] = -1; //■■■■■
24 difNo[difCnt++] = atoi(pDesCdrField_t->strNo); //■■■■■
25 } // else if(strValue != pSrcCdrField_t->strValue)
26 else
27 {
28 m_pDesCdrArray->RemoveAt(index);
29 difNo[difCnt++] = -2; //■■■■■
30 } // else
31 } // for(int cnt = 0; cnt < (int)m_pSrcCdrArray->GetCount(); cnt++)
32 for(int cnt = 0; cnt < (int)m_pDesCdrArray->GetCount(); cnt++)
33 {
34 // get the current CDR field
35 pDesCdrField_t = ( g_pCdrField_t )m_pDesCdrArray->GetAt(cnt);
36
37 // find the position
38 int arrayCnt;
39 for(arrayCnt = (int)diffArray.GetCount()-1; arrayCnt >= 0; arrayCnt--)
40 {
41 CString strTemp = diffArray.GetAt(arrayCnt);
42 CString a = getNo(strTemp);
43
44 if(atoi(pDesCdrField_t->strNo) > difNo[arrayCnt] && difNo[arrayCnt] > 0) //■■■■■
45 {
46 break;
47 } // if(pDesCdrField_t->strNo < getNo(strTemp))
48 }// for(arrayCnt = 0; arrayCnt < (int)diffArray.GetCount(); arrayCnt++)
49
50 CString strLine;
51 strLine = _T(">") + pDesCdrField_t->strLine + _T("\n\n");
52 if(arrayCnt == -1)
53 {
54 arrayCnt = 0;
55 }
56 diffArray.InsertAt(arrayCnt, strLine);
57 } //for(int cnt = 0; cnt < (int)m_pDesCdrArray->GetCount(); cnt++)
58
59 index = strSrcFilePath.ReverseFind('\\');
60 len = strSrcFilePath.GetLength();
61 strDiffName = strSrcFilePath.Mid(index+1, len-index-5);
62 strDiffName = _T("diff_") + strDiffName + _T(".txt");
63 strDifFilePath += _T("\\") + strDiffName;
64
65 CFileFind fileFind;
66
67 if(fileFind.FindFile(strDifFilePath))
68 {
69 return -1;
70 }
71
72 if( !file.Open(strDifFilePath, CFile::modeCreate|CFile::modeWrite) )
73 {
74 return DIFF_FAIL;
75 } // if( !file.Open(strDifFilePath, CFile::modeCreate|CFile::modeWrite) )
76
77 len = (int)diffArray.GetCount();
78 for( int cnt = 0; cnt < len; cnt++)
79 {
80 CString strLine = diffArray.GetAt(cnt);
81 file.WriteString(strLine);
82 } // for( int cnt = 0; cnt < len; cnt++)
83 file.Close();
84
85 CString strSrcName;
86 index = strSrcFilePath.ReverseFind('\\');
87 strSrcName = strSrcFilePath.Right(strSrcFilePath.GetLength() - index -1);
88 if(len == 0)
89 {
90 m_difResFile.WriteString(strSrcName + ": OK\n");
91 }
92 else
93 {
94 m_difResFile.WriteString(strSrcName + ": NG\n");
95 }
96
97 return CDR_SUCCESS;
————————————————————————————————————————————————————————————————————————————————————————————————————
...全文
59 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnzdgs 2008-02-22
  • 打赏
  • 举报
回复
new的时候分配足够大的内存,或者定义成array<int^>^difNo使用时动态调整size。
BlueAsuro 2008-02-22
  • 打赏
  • 举报
回复
用K7查一下吧 把可疑的都拿出来 一个个检查
  • 打赏
  • 举报
回复
你只分配了一个int.
然后你用的时候越过了很多
应该分配的长度应该比 m_pSrcCdrArray这个数组里面的数据多.

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧