那天回答我问题的大侠们(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)
...全文
27 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ys810 2003-06-10
  • 打赏
  • 举报
回复
打包时少加了些文件,具体我现在也不知道
ys810 2003-06-06
  • 打赏
  • 举报
回复
////////////////////////得到日期,时间字符串,此时时间串是从文件名直接提取,所以不需要time shift/////////////
name = AnsiString(fileName).SubString(4,8);
//convert date format yyyymmdd to yyyy-mm-dd
tokens[2] = strcpy(dateTime, (name.SubString(1,4)+"-"+name.SubString(5,2)+"-"+name.SubString(7,2)).c_str());
//change hour string to "hh:00:00"
tokens[1] = strcpy(eTIME, (AnsiString(fileName).SubString(13,2)+ ":00:00").c_str());
i = StrToInt(AnsiString(fileName).SubString(13,2));
i--; //begin time在endtime前一个小时
if(i <10)
{
tokens[0]= strcpy(bTIME ,("0"+IntToStr(i)+ ":00:00").c_str());
}
else
{
tokens[0]= strcpy(bTIME ,(IntToStr(i)+ ":00:00").c_str());
}
///////////////////////////////////////////////////////////////

name = AnsiString(fileName);
if(name.Pos(sVersion) == 0) //说明是旧版本的文件名,没有包含B6,B7标志
{
name = name + "_"+ sVersion;
}

tableName_pvc = name + SUFFIX_PVC;
tableName_bearer = name + SUFFIX_BEARER;
tableName_cell = name + SUFFIX_CELL;
tableName_bsc = name + SUFFIX_BSC;
tableName_lapd = name + SUFFIX_LAPD;
tableName_cellInd = name + SUFFIX_CELL_INDICATOR;
tableName_bscInd = name + SUFFIX_BSC_INDICATOR;
tableName_netInd = sVersion + "_" + TABLENAME_NET; //不带后缀的全网数据文件
tableName_group = name + SUFFIX_GROUP;

//1. 写pvc数据
strcpy(fieldName_pvc, lines_pvc[0]);
table_pvc = createTable_GPRS(tableName_pvc, fieldName_pvc); //建立一个空表,字段没有内容
if(table_pvc)
{
table_pvc->Active = true;
}
else
{
return; //创建表被用户取消或是没有成功
}
writeLines_GPRS(tokens, lines_pvc, table_pvc, offsetPvc); //写入该表的内容
table_pvc->Active = false;
listData->Update();


//2. 写bearer数据
strcpy(fieldName_bearer, lines_bearer[0]);
table_bearer = createTable_GPRS(tableName_bearer, fieldName_bearer);
if(table_bearer)
{
table_bearer->Active = true;
}
else
{
return; //创建表被用户取消或是没有成功
}
writeLines_GPRS(tokens, lines_bearer, table_bearer, offsetBearer);
table_bearer->Active = false;
listData->Update();

//3. 写cell数据
strcpy(fieldName_cell, lines_cell[0]);
table_cell = createTable_GPRS(tableName_cell, fieldName_cell);
if(table_cell)
{
table_cell->Active = true;
}
else
{
return; //创建表被用户取消或是没有成功
}
writeLines_GPRS(tokens, lines_cell, table_cell, offsetCell);

table_cell->Active = false;
listData->Update();


//4. 写BSC数据
strcpy(fieldName_bsc, lines_bsc[0]);
table_bsc = createTable_GPRS(tableName_bsc, fieldName_bsc);
if(table_bsc)
{
table_bsc->Active = true;
}
else
{
return; //创建表被用户取消或是没有成功
}

writeLines_GPRS(tokens, lines_bsc, table_bsc, offsetBsc);
table_bsc->Active = false;
listData->Update();

//5. 写LAPD数据
strcpy(fieldName_lapd, lines_lapd[0]);
table_lapd = createTable_GPRS(tableName_lapd, fieldName_lapd);
if(table_lapd)
{
table_lapd->Active = true;
}
else
{
return; //创建表被用户取消或是没有成功
}

writeLines_GPRS(tokens, lines_lapd, table_lapd, offsetLapd);
table_lapd->Active = false;
listData->Update();

//6.写cell indicator

DM->Table1->Active = false;
DM->Table1->DatabaseName = "OMCR";
DM->Table1->TableType =ttDBase;
DM->Table1->TableName=tableName_cellInd;
if(DM->Table1->Exists)
{
DM->Table1->DeleteTable();
}
DM->Table1->CreateTable();
table_cellInd = DM->Table1;

writeToken_GPRSInd(table_cellInd, tableName_cell);
if(cb_check & sVersion == "B6")
{
table_cellInd->Active = false;
CheckDataValid(table_cellInd, 8); // 小区指标检查从第9列开始,前面是小区名字和时间等信息
}
table_cellInd->Active = false;
listData->Update();

//6.写BSC indicator

DM->Table1->Active = false;
DM->Table1->DatabaseName = "OMCR";
DM->Table1->TableType =ttDBase;
DM->Table1->TableName=tableName_bscInd;
if(DM->Table1->Exists)
{
DM->Table1->DeleteTable();
}

DM->Table1->CreateTable();
table_bscInd = DM->Table1;

writeToken_GPRSIndBSC(table_bscInd, tableName_group);
if(cb_check)
{
table_bscInd->Active = false;
CheckDataValid(table_bscInd, 4); //BSC指标的表从第五列开始
}
table_bscInd->Active = false;
listData->Update();

//7.写Network indicator
//table_netInd = createTable_GPRSInd(tableName_netInd); //如果用户再次对同一时刻的原始数据进行计算的话,会产生冗余数据
DM->Table1->Active = false;
DM->Table1->DatabaseName = "OMCR";
DM->Table1->TableType =ttDBase;
DM->Table1->TableName=tableName_netInd;
if(DM->Table1->Exists) //net ind文件存在,只需在后面添加记录
{
blNewCreate = false;
}
else //net ind文件不存在,创建
{
DM->Table1->CreateTable();
blNewCreate = true;
}

table_netInd = DM->Table1;

if(!blNewCreate)
{
DM->Query4->Active = false;
DM->Query4->DatabaseName = "OMCR";
DM->Query4->SQL->Clear();
DM->Query4->SQL->Add("select * from ");
DM->Query4->SQL->Add(tableName_netInd);
DM->Query4->SQL->Add(" where dateTime='" + AnsiString(dateTime) +"' and" + " eTIME='" + AnsiString(eTIME)+ "'");
DM->Query4->Active= true;
if(DM->Query4->RecordCount > 0) //该时段的全网指标已经计算过
{
DM->Query4->Active = false;
table_netInd->Active = false;
return;
}
}

table_netInd->Active = true;
writeToken_GPRSIndNET(table_netInd, blNewCreate, tableName_group); //通过计算tableName_cell中的数据得出全网指标并存放在table_netInd中


if(cb_check)
{
table_netInd->Active = false;
CheckDataValid(table_netInd, 4); //全网指标表从第4列开始检查,注意是从0开始
}
table_netInd->Active = false;
listData->Update();

//7.写group指标
if(cb_group)
{
write_group(tableName_cellInd, tableName_cell);
}

}
ys810 2003-06-06
  • 打赏
  • 举报
回复
没错,是我本意,指针数组

//TODO: Add your source code here
bool binMaskHint = false;
char *line;
char *lines_pvc[LINENUM_GPRS]; //存放pvc数据
char *lines_bearer[LINENUM_GPRS]; //存放BearerChannel数据
char *lines_cell[LINENUM_GPRS]; //存放小区数据
char *lines_bsc[LINENUM_GPRS]; //存放pvc数据
char *lines_lapd[LINENUM_GPRS]; //存放lapd数据
char fieldName_pvc[LINENUM_GPRS], fieldName_bearer[LINENUM_GPRS], fieldName_cell[LINENUM_GPRS], fieldName_bsc[LINENUM_GPRS], fieldName_lapd[LINENUM_GPRS];
bool isPvc = false, isBearer = false, isCell = false, isBsc = false, isLapd = false;
bool blNewCreate = false; //用于表明改全网指标文件是否为新建
int offsetPvc = 0, offsetBearer = 0, offsetCell = 0, offsetBsc = 0, offsetLapd = 0;
AnsiString tableName_pvc, tableName_bearer, tableName_cell, tableName_bsc, tableName_lapd, tableName_cellInd, tableName_bscInd,tableName_netInd, name;
AnsiString tableName_group;
TTable *table_pvc, *table_bearer, *table_cell, *table_bsc, *table_lapd, *table_cellInd, *table_bscInd, *table_netInd;

char *tokens[TOKENNUM]; //存放从头文件中读取的TOKEN,指时间,starttime endtime TOKENNUM=10
char dateTime[TOKENNUM_GPRS],bTIME[TOKENNUM_GPRS],eTIME[TOKENNUM_GPRS]; //存放日期,开始/结束时间
//AnsiString dateTime,bTIME,eTIME;
char *token;
int i;

//初始化

for(i=0; i<LINENUM_GPRS; i++)
{
lines_pvc[i] = "-";
lines_bearer[i] = "-";
lines_cell[i] = "-";
lines_bsc[i] = "-";
lines_lapd[i] = "-";
}

i = strlen(buffer);
//if(strlen(buffer)<=0) //buffer就是传进来的txt文件内容
if(i <= 0)
{
Application->MessageBoxA("读文件错误!",MB_TITLE, MB_OK);
return;
}

//1. 读头文件行
line = strtok(buffer, "\n");
for(int i =0; i < 7; i++) //将文件前面无关的7行过滤
{
strtok(NULL, "\n");
}

tokens[0] = strtok(NULL, "\n"); //bTimeLine ,start time
tokens[1] = strtok(NULL, "\n"); //eTimeLine ,end time
tokens[2] = strtok(NULL, "\n"); //dateLine ,date
//这里不能打断,否则strtok函数无法继续下去

//2. 读数据行
while((line = strtok(NULL, "{}")))
{
if(isPvc) //第一次执行到此是\npvc
{
lines_pvc[offsetPvc]=line;
offsetPvc++;
isPvc = false;
}
if(isBearer)
{
lines_bearer[offsetBearer]=line;
offsetBearer++;
isBearer = false;
}
if(isCell)
{
lines_cell[offsetCell]=line;
offsetCell++;
isCell = false;
}
if(isBsc)
{
lines_bsc[offsetBsc]=line;
offsetBsc++;
isBsc = false;
}
if(isLapd)
{
lines_lapd[offsetLapd] = line;
offsetLapd++;
isLapd = false;
}

AnsiString temp = line;
if(temp.Trim() == "pvc")
{
isPvc = true;
}
if(temp.Trim() == "BearerChannel")
{
isBearer = true;
}
if(temp.Trim().LowerCase() == "cell")
{
isCell = true;
}
if(temp.Trim() == "BSC")
{
isBsc = true;
}
if(temp.Trim() == "LapD")
{
isLapd = true;
}
}

kingfish 2003-06-06
  • 打赏
  • 举报
回复
没贴全

char *lines_pvc[LINENUM_GPRS]; //是你的本意吗?还是想定义一个char lines_pvc[LINENUM_GPRS];

ys810 2003-06-06
  • 打赏
  • 举报
回复
void TformMain::readWriteFile_GPRS(char * buffer, char * fileName)
{
//TODO: Add your source code here
bool binMaskHint = false;
char *line;
char *lines_pvc[LINENUM_GPRS]; //存放pvc数据
char *lines_bearer[LINENUM_GPRS]; //存放BearerChannel数据
char *lines_cell[LINENUM_GPRS]; //存放小区数据
char *lines_bsc[LINENUM_GPRS]; //存放pvc数据
char *lines_lapd[LINENUM_GPRS]; //存放lapd数据

char *tokens[TOKENNUM]; //存放从头文件中读取的TOKEN,指时间,starttime endtime TOKENNUM=10
char dateTime[TOKENNUM_GPRS],bTIME[TOKENNUM_GPRS],eTIME[TOKENNUM_GPRS]; //存放日期,开始/结束时间
//AnsiString dateTime,bTIME,eTIME;
char *token;
int i;

//初始化

for(i=0; i<LINENUM_GPRS; i++)
{
lines_pvc[i] = "-";
lines_bearer[i] = "-";
lines_cell[i] = "-";
lines_bsc[i] = "-";
lines_lapd[i] = "-";
}


if(strlen(buffer)<=0) //buffer就是传进来的txt文件内容
{
Application->MessageBoxA("读文件错误!",MB_TITLE, MB_OK);
return;
}

//1. 读头文件行
line = strtok(buffer, "\n");
ys810 2003-06-06
  • 打赏
  • 举报
回复
问题是在我的机器和其他许多人机器上(released vesion)运行都没有问题,只有两个用户机器上运行报错,而且错误非常类似,不知为何
kingfish 2003-06-06
  • 打赏
  • 举报
回复
跟一下,主要是strtok的地方
kingfish 2003-06-05
  • 打赏
  • 举报
回复
Access overrun: Attempt to access 2031 byte(s) at 0x04B4DAC0, that is at heap
block 0x04B4DAC0 which is only 2030 bytes long.

把readWriteFile贴出来
书生 2003-06-05
  • 打赏
  • 举报
回复
昏一会先,我出去了。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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