下面这段代码我在测试运行时读取和发送都能正常执行,但是读取结束后的fclose时,程序就会崩溃
,其中文件指针是全局的,读取时的大小是一次1024个字节,GDB调试出来好像是内存非法,但是看不出哪里的问题,请大佬帮忙看下,谢谢
int msgDealFunc(unsigned char *buf)
{
char sendBuf[1500+1]={0};
char fileContent[1024+1]={0};
int sendLen = 0;
short int readLen = 0;
int fromStartBytes = 0;
char nameBuf[128]={0};
int fileSize = 0;
int spliteNum = 0;
int loseId = 0;
int index;
long filePosition =0;
printf("1111111111111111111\n");
if(buf[0]==0x02&&buf[1]==0x00)
{
sprintf(nameBuf,"%s/%s",FILEPATHDIR,FILENAME);
fileSendInfoT.fileSend = fopen(nameBuf,"rb");
printf("22222222222222222222222\n");
for(index =1;index<1025;index++)
{
printf("333333333333333333333333333\n");
fromStartBytes = ftell(fileSendInfoT.fileSend);
printf("44444444444444444444444444444444\n");
readLen = fread(fileContent,sizeof(char),SPLITESIZE,fileSendInfoT.fileSend);
printf("55555555555555555555555555555\n");
if(readLen > 0)
{
sendLen = makeMsg101(sendBuf,fileContent,readLen,index,fromStartBytes);
printf("6666666666666666666666\n");
udpSend(UNICAST, sendBuf, sendLen);
printf("77777777777777777777\n");
idWithPositionT[index].position = fromStartBytes;
sendAdd++;
}
else
{
break;
}
}
fclose(fileSendInfoT.fileSend);
sendLen = makeMsg110(sendBuf,index-1);
udpSend(UNICAST,sendBuf,sendLen);
//fileSendInfoT.groupNumRecord++;
}