473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

when it reaches end-of-file (stop=1) segmentation fault

365 100+
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)


Expand|Select|Wrap|Line Numbers
  1. int main(int argc, const char * argv[])
  2. {
  3.         time_stamp_t TS;
  4.         DATA_T meta;
  5.         int stop=0;
  6.         int metagen_ptr;
  7.  
  8.         FileLoaderStart("Receiver.ini");
  9.  
  10.         while (1) {
  11.                 FileLoader(&TS, &meta, &stop,  &metagen_ptr);
  12.                 if (stop == 1){
  13.                         return 0;
  14.                 }
  15.                 printf("TS: %d:%d:%d:%d\n", TS.hourofday, TS. minuteofhour, TS.secofminute, TS.millisec);
  16.  
  17.                 //sleep(1);
  18.         }
  19.  
  20.         return 0;
  21. }
  22.  
  23. void FileLoaderStart(char*cfgfile)
  24. {
  25.    char metafilename[50];
  26.    META_DATA_T meta;
  27.  
  28.         memset(metafilename,'\0',CFG_FILE_NAME_LENGTH);
  29.         htGetParam(cfgfile,"metafilename",metafilename);
  30.  
  31.         fmetafile=fopen(metafilename,"r");
  32.         if(fmetafile==NULL)return;
  33.  
  34.         memset(linebuffer,0,81920);
  35.  
  36.         if(fgets(linebuffer,MAX_LINE_SIZE,fmetafile)==NULL){
  37.                 fclose(fmetafile);
  38.                 fmetafile=NULL;
  39.                 return;
  40.         }
  41.  
  42.          FileParseOneLine(linebuffer,&pre_TS,&pre_meta);
  43.  
  44. }
  45.  
  46.  
  47.  
  48. void FileLoader(time_stamp_t* time_stamp, DATA_T* blob_array,int*stop,int*metagen_ptr)
  49. {
  50.  
  51.  
  52.         time_stamp_t TS;
  53.         DATA_T meta;
  54.         int blob_index=0;
  55.         DATA_T* blob_ptr=blob_array;
  56.  
  57.         memset(blob_array,0,sizeof(DATA_T)*MAX_BLOB_NUM);
  58.         *stop=0;
  59.  
  60.  
  61.  
  62.  
  63.         while(1){
  64.                 memset(linebuffer,0,81920);
  65.                 if(fgets(linebuffer,MAX_LINE_SIZE,fmetafile)==NULL){
  66.                         fclose(fmetafile);
  67.                         *stop=1;
  68.                         return ;
  69.                 }
  70.  
  71.                 MetaFileParseOneLine(linebuffer,&TS,&meta);
  72.                 if(pre_TS.year==TS.year &&pre_TS.month==TS.month&&pre_TS.dayofmonth==TS.dayofmonth
  73.             &&pre_TS.hourofday==TS.hourofday&& pre_TS.minuteofhour==TS.minuteofhour&& pre_TS.secofminute==TS.secofminute
  74.                 &&pre_TS.millisec==TS.millisec&&blob_index<MAX_BLOB_NUM){
  75.  
  76.  
  77.  
  78. }
  79.  
  80.  
Feb 23 '10 #1
4 4003
tvnaidu
365 100+
I added more prints, segmentation fault coming from main function only, when I check stop == 1 then return, that return causing this violation, but when I reaches EOF, I want to exit the prog.
Feb 23 '10 #2
tvnaidu
365 100+
GDB shows line 61 fgets, any command to view what causes violation?

TS: 18:58:57:791
***EOF ****

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1077195904 (LWP 9254)]
0x402835aa in fgets () from /lib/tls/libc.so.6
(gdb) bt
#0 0x402835aa in fgets () from /lib/tls/libc.so.6
#
Feb 23 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
Ot ook like you are passing the address of:

Expand|Select|Wrap|Line Numbers
  1. DATA_T meta; 
to your FileLoader function as the address of an array of DATA_T, which it's not.
Feb 24 '10 #4
tvnaidu
365 100+
Thanks, I found it. now it works.
Feb 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Beau E. Cox | last post by:
Hi - I have an application which is essentially 'read-only' - once the database is loaded it is only read from. So, I am trying to implement it with various indices and a table containg some...
0
by: David | last post by:
Hello I have made a component (MyWebForm) that inherits Page. This component have a method called 'ComponentAdded' that shows a msgbox if it is in design mode: Public Class MyWebForm Inherits...
4
by: Rich Wallace | last post by:
Hi all, I have a VB app that runs and manages individual XLS files within a single COM object. Upon processing the final fie, I attempt to close out the EXCEL object and release it using...
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
3
by: Sehboo | last post by:
Hi, Is it possible that you can monitor your memory usage and kill some process when memory usage reaches 80% or so? I have an application which uses lot of memory and then system hangs, but...
5
by: raulavi | last post by:
vb VS 2003 Hi all: thanks to all in advance for your responses. my app displays the form , then when it reaches a debbuging point the form is blanked, (it just shows the frame around the form) I...
18
by: Seeker | last post by:
I essentially copied this program from K&R: #include <stdio.h> #include <stdlib.h> int main() { int c;
2
by: philip | last post by:
hello i am learning how to write stored procedures in sql server, i would like to know what's wrong with the following statement? please help the management studio gives me the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.