When I reach end-of-file, I gets segmentation fault with below prog, I just read from a file, then print the time stamp, when reaches end-of-file, sets "stop=1", but my program dumps core, any idea?.
TS: 18:58:57:291
TS: 18:58:57:385
TS: 18:58:57:494
TS: 18:58:57:588
TS: 18:58:57:682
TS: 18:58:57:791
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1077195904 (LWP 6583)]
0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
(gdb)
TS: 18:58:57:291
TS: 18:58:57:385
TS: 18:58:57:494
TS: 18:58:57:588
TS: 18:58:57:682
TS: 18:58:57:791
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1077195904 (LWP 6583)]
0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
(gdb)
Code:
int main(int argc, const char * argv[])
{
time_stamp_t TS;
DATA_T meta;
int stop=0;
int metagen_ptr;
FileLoaderStart("Receiver.ini");
while (1) {
FileLoader(&TS, &meta, &stop, &metagen_ptr);
if (stop == 1){
return 0;
}
printf("TS: %d:%d:%d:%d\n", TS.hourofday, TS. minuteofhour, TS.secofminute, TS.millisec);
//sleep(1);
}
return 0;
}
void FileLoaderStart(char*cfgfile)
{
char metafilename[50];
META_DATA_T meta;
memset(metafilename,'\0',CFG_FILE_NAME_LENGTH);
htGetParam(cfgfile,"metafilename",metafilename);
fmetafile=fopen(metafilename,"r");
if(fmetafile==NULL)return;
memset(linebuffer,0,81920);
if(fgets(linebuffer,MAX_LINE_SIZE,fmetafile)==NULL){
fclose(fmetafile);
fmetafile=NULL;
return;
}
FileParseOneLine(linebuffer,&pre_TS,&pre_meta);
}
void FileLoader(time_stamp_t* time_stamp, DATA_T* blob_array,int*stop,int*metagen_ptr)
{
time_stamp_t TS;
DATA_T meta;
int blob_index=0;
DATA_T* blob_ptr=blob_array;
memset(blob_array,0,sizeof(DATA_T)*MAX_BLOB_NUM);
*stop=0;
while(1){
memset(linebuffer,0,81920);
if(fgets(linebuffer,MAX_LINE_SIZE,fmetafile)==NULL){
fclose(fmetafile);
*stop=1;
return ;
}
MetaFileParseOneLine(linebuffer,&TS,&meta);
if(pre_TS.year==TS.year &&pre_TS.month==TS.month&&pre_TS.dayofmonth==TS.dayofmonth
&&pre_TS.hourofday==TS.hourofday&& pre_TS.minuteofhour==TS.minuteofhour&& pre_TS.secofminute==TS.secofminute
&&pre_TS.millisec==TS.millisec&&blob_index<MAX_BLOB_NUM){
}
Comment