Thread: how to fix "Segmentation fault (core dumped)"

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    how to fix "Segmentation fault (core dumped)"

    how to fix "Segmentation fault (core dumped)"--error

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by kapil1089thekin View Post
    how to fix "Segmentation fault (core dumped)"--error
    Erm... By fixing the bug that causes it?
    Seriously, a segmentation fault can be caused by countless of things: buffer overflows, dereferencing dangling pointers, double frees, writing to read-only memory and loads more.

    You should really post the code or find out what causes the segmentation fault. If you program with Linux run the program with valgrind and you'll get some useful information.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    134
    this is the function which causes the problem I have even found the line which gives me the error

    Code:
                    set<int> eTransition(set<int> s)        {
                            set<int> eSet;
                            set<int>::iterator itTemp;
                            queue<int> que;
                            int pop;
                            set<int> processed;
                            for(it = s.begin();it!=s.end();it++)    {
    
                                    itTemp = eSet.find(*it);
                                    if(itTemp != eSet.end())        {       // element is in the set so continue without executing anything                 
                                            continue;
                                    }
                                    //element is not in the set so insert it in the set and find its etransitions
                                    que.push(*it);
                                    eSet.insert(*it);
                                    while(!que.empty())     {
                                            pop=que.front();
                                            que.pop();
                                            int i;
                                            for(i=0;i<nfaTransition.size();i++)     {
                                                    if(nfaTransition[i].state==pop) {
                                                            break;
                                                    }
                                            }
                                            for(int j=0;j<nfaTransition[i].linke.size();j++)        {
                                                    itTemp = eSet.find(nfaTransition[i].linke[j]);
                                                    if(itTemp == eSet.end())        {
                                                            que.push(nfaTransition[i].linke[j]);     //if I comment this line I don't get error
                                                            eSet.insert(nfaTransition[i].linke[j]);
                                                    }
                                            }
                                    }
    
                            }
                            return(eSet);
                    }

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    134
    and how can I start going with Valgrind?

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    The Valgrind website sounds like a good starting point.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Code:
                                            for(i=0;i<nfaTransition.size();i++)     {
                                                    if(nfaTransition[i].state==pop) {
                                                            break;
                                                    }
                                            }
    At this point i will be equal to nfaTransition.size().

    Code:
                                            for(int j=0;j<nfaTransition[i].linke.size();j++)        {
                                                    itTemp = eSet.find(nfaTransition[i].linke[j]);
                                                    if(itTemp == eSet.end())        {
                                                            que.push(nfaTransition[i].linke[j]);     //if I comment this line I don't get error
                                                            eSet.insert(nfaTransition[i].linke[j]);
                                                    }
                                            }
    i is still equal to nfaTransition.size(). Which means you're using nfaTransition[nfaTransition.size()]. This is illegal: the range is from 0 to .size()-1.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. couple of questions concerning multi core cpu's
    By Masterx in forum Tech Board
    Replies: 6
    Last Post: 10-07-2009, 10:39 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. Core Dump / Segmentation Fault
    By Inquirer in forum Linux Programming
    Replies: 2
    Last Post: 04-08-2003, 08:24 PM
  5. Segmantation Fault (core dumped) error
    By Vinnie66 in forum C Programming
    Replies: 6
    Last Post: 03-25-2002, 01:34 PM