Hi,

I am getting the error "Segmentation fault" when i run my program. Then when i debug the code to find the cause of the error i get the following error messages. I do not know what these error messages mean:

Error Message:
------------------------------------------------------------------
Program received signal SIGSEGV, Segmentation fault.
0x67656c6c in ?? ()
(gdb) n
Cannot find bounds of current function
--------------------------------------------------------------------

The error messages are generated when i debug at line number 429 in the following function correct_file which is a member function the class circuit. The function is used to modify one line in the file *ftp.

410 int circuit::correct_file(int no1, int no2, char *ftp)
    411 {
    412         // The following part of the code corrects the line in file
    413         deque <string> text_1;
    414         std::string s2,t2;
    415         /* Counting the number of original lines in the file */
    416         ifstream ficnf;
    417         int size_f = 0;
    418 
    419         /* Count the number of lines in the file */
    420         std::string linef;
    421         ficnf.open(ftp,ios::in);
    422         if (!ficnf.is_open())
    423         {
    424                 cout<< "Error opening file" << "\n";
    425                 exit(-1);
    426         }
    427         else
    428         {
    429                 while(getline(ficnf,linef))
    430                 {
    431                         size_f++;
    432                 }
    433 
    434                 ficnf.close();
    435         }

The getline statement seems fine to me but the error is coming at this line. Also the error occurs when i call the function "correct_file" the second time and not the first time.

Any help is appreciated.

Thanks

Can you extract and post the shortest example possible that will generate this problem? (so that we can compile it to track down the problem, but not have to look at 400+ lines of code)

Dave

429 while(getline(ficnf,linef))

add an breakpoint to here and just inspect the parameters fincf and
linef. You will find the answer.

looks like there is no delim '\n', looks like that buffer overflows and it goes to read some memory location outside the segment , This is a possible cause of this error.

How can i check the buffer overflow or reading from some memory location outside the segment. I will try to post a small code....

This article has been dead for over six months. Start a new discussion instead.