那天回答我问题的大侠们(libran,kingcaiyao,qibo999,zahuifan),接分了,关于access violation,通过codeguard是有些有用的冬冬,但还
ys810 2003-06-05 07:00:39 程序很短,请各位稍微耐心一下,谢谢
主程序:
打开一个长2030byte的文件
iFileHandle = FileOpen(fileName, fmOpenRead);
iFileLength = FileSeek(iFileHandle,0,2); //指针移到文件末,返回文件长度
FileSeek(iFileHandle,0,0); //指针移到文件头
pszBuffer = new char[iFileLength+1]; //pszBuffer存放txt文件中的内容
iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
FileClose(iFileHandle);
然后调用子程序
readWriteFile_GPRS(pszBuffer, shortName);
//程序原型是readWriteFile_GPRS(char * buffer, char * fileName)
子程序中
根据code guard地提示,主要是两个地方(几乎就在变量申明之后,变量申明中有大量的char *[2000]等数组)
出错的地方由*****标出
*****if(strlen(buffer)<=0) //buffer就是传进来的txt文件内容
{
Application->MessageBoxA("读文件错误!",MB_TITLE, MB_OK);
return;
}
//1. 读头文件行
*****line = strtok(buffer, "\n");
如果解决问题,另送100分!!
以下是code guard提到的错误,供参考
Error 00142. 0x130410 (Thread 0x04AC):
Access overrun: Attempt to access 2031 byte(s) at 0x04B4DAC0, that is at heap
block 0x04B4DAC0 which is only 2030 bytes long.
strlen(0x04B4DAC0 ["#%npr MFS\n#\n{\n{\nMFS 501\nVERSION
MFSSAT48.48P\nITFVERSION 3\nScannerIdentity 1\nSTARTTIME 00:00:00\nENDTIME
01:00:00\nDATE 2003-05-23\n\npvc {\nTP 16847874\nBearer 2\nPVC 46\nSF 0\nP4
0\nP5 0\nP23 0\nP34 0\nP45 27\nP46 100\nP6c 0\nP6d 0\n}\nBearerChannel {\nTP
16847874\nBearer 2\nSF 0\nP6a 0\nP6b 0\nP33 0\nP3a 0\nP3b 0\n}\nLapD {\nBSS
9\nTP 16847873\nGSL 34\nSF 0\nP41 217\nP42 210\nP32 0\nP2a 0\nP2b 0\nP2c
0\nP2d 0\n}\nCell {\nBSS 9\nFABRIC 16847872\nLAC 22323\nCI 33401\nMIN_PDCH
1\nMAX_PDCH 6\nBS_PBCCH_BLKS 3\nBS_PAG_BLKS_RES 2\nBS_PRACH_BLKS 2\nSF 0\nP10
0\nP9 29\nP14 0\nP15 2\nP22 114\nP27 0\nP28 13\nP43 878\nP44 3864\nP1 0\nP11
0\nP16 898\nP19 87\nP24 0\nP29 39\nP65 0\nP66 0\nP35 2\nP36 0\nP39 1\nP40
0\nP49 135\nP67 0\nP38 48150\nP53a 22\nP53b 0\nP54 92\nP13 0\nP26 0\nP105c
0\nP105d 0\nP105e 0\nP105f 0\nP105g 0\nP105h 0\nP146 0\nP147 0\nP149
13\nP149a 13\nP150 4\nP153b 44\nP154b 132\nP160 0\nP161 119\nP162 2\nP163
0\nP164 30\nP165 0\nP166 0\nP167 0\nP168 10\nP169 0\nP302b 12\nP302c 5\nP303a
0\nP303...])
Call Tree:
0x00421594(=omceProj.exe:0x01:020594) C:\Program Files\Borland\CBuilder6\Projects\GPRS Indicator Caculator\omcr.cpp#3521
0x00407125(=omceProj.exe:0x01:006125) C:\Program Files\Borland\CBuilder6\Projects\GPRS Indicator Caculator\omcr.cpp#477
0x4010798A(=vcl60.bpl:0x01:05698A)
0x401075BF(=vcl60.bpl:0x01:0565BF)
0x4010A83D(=vcl60.bpl:0x01:05983D)
0x4010A623(=vcl60.bpl:0x01:059623)
The object array (0x04B4DAC0) [size: 2030 bytes] was created with new[]
Call Tree:
0x00406E84(=omceProj.exe:0x01:005E84) C:\Program Files\Borland\CBuilder6\Projects\GPRS Indicator Caculator\omcr.cpp#452
0x4010798A(=vcl60.bpl:0x01:05698A)
0x401075BF(=vcl60.bpl:0x01:0565BF)
0x4010A83D(=vcl60.bpl:0x01:05983D)
0x4010A623(=vcl60.bpl:0x01:059623)
0x4003947A(=rtl60.bpl:0x01:03847A)
------------------------------------------
Error 00143. 0x130410 (Thread 0x04AC):
Access overrun: Attempt to access 2031 byte(s) at 0x04B4DAC0, that is at heap
block 0x04B4DAC0 which is only 2030 bytes long.
strtok(0x04B4DAC0 ["#%npr MFS\n#\n{\n{\nMFS 501\nVERSION
MFSSAT48.48P\nITFVERSION 3\nScannerIdentity 1\nSTARTTIME 00:00:00\nENDTIME
01:00:00\nDATE 2003-05-23\n\npvc {\nTP 16847874\nBearer 2\nPVC 46\nSF 0\nP4
0\nP5 0\nP23 0\nP34 0\nP45 27\nP46 100\nP6c 0\nP6d 0\n}\nBearerChannel {\nTP
16847874\nBearer 2\nSF 0\nP6a 0\nP6b 0\nP33 0\nP3a 0\nP3b 0\n}\nLapD {\nBSS
9\nTP 16847873\nGSL 34\nSF 0\nP41 217\nP42 210\nP32 0\nP2a 0\nP2b 0\nP2c
0\nP2d 0\n}\nCell {\nBSS 9\nFABRIC 16847872\nLAC 22323\nCI 33401\nMIN_PDCH
1\nMAX_PDCH 6\nBS_PBCCH_BLKS 3\nBS_PAG_BLKS_RES 2\nBS_PRACH_BLKS 2\nSF 0\nP10
0\nP9 29\nP14 0\nP15 2\nP22 114\nP27 0\nP28 13\nP43 878\nP44 3864\nP1 0\nP11
0\nP16 898\nP19 87\nP24 0\nP29 39\nP65 0\nP66 0\nP35 2\nP36 0\nP39 1\nP40
0\nP49 135\nP67 0\nP38 48150\nP53a 22\nP53b 0\nP54 92\nP13 0\nP26 0\nP105c
0\nP105d 0\nP105e 0\nP105f 0\nP105g 0\nP105h 0\nP146 0\nP147 0\nP149
13\nP149a 13\nP150 4\nP153b 44\nP154b 132\nP160 0\nP161 119\nP162 2\nP163
0\nP164 30\nP165 0\nP166 0\nP167 0\nP168 10\nP169 0\nP302b 12\nP302c 5\nP303a
0\nP303...], 0x004F64FB ["\n"])
Call Tree:
0x0042169C(=omceProj.exe:0x01:02069C) C:\Program Files\Borland\CBuilder6\Projects\GPRS Indicator Caculator\omcr.cpp#3528
0x00407125(=omceProj.exe:0x01:006125) C:\Program Files\Borland\CBuilder6\Projects\GPRS Indicator Caculator\omcr.cpp#477
0x4010798A(=vcl60.bpl:0x01:05698A)
0x401075BF(=vcl60.bpl:0x01:0565BF)
0x4010A83D(=vcl60.bpl:0x01:05983D)
0x4010A623(=vcl60.bpl:0x01:059623)
The object array (0x04B4DAC0) [size: 2030 bytes] was created with new[]
Call Tree:
0x00406E84(=omceProj.exe:0x01:005E84) C:\Program Files\Borland\CBuilder6\Projects\GPRS Indicator Caculator\omcr.cpp#452
0x4010798A(=vcl60.bpl:0x01:05698A)
0x401075BF(=vcl60.bpl:0x01:0565BF)
0x4010A83D(=vcl60.bpl:0x01:05983D)
0x4010A623(=vcl60.bpl:0x01:059623)
0x4003947A(=rtl60.bpl:0x01:03847A)