Segmentation fault

Apr 24, 2014 at 1:25am
After running this piece of code I get a message from gdb saying that
curr = curr -> next; causes a seg fault. I don't know why. Any help that could be given would be appreciated.


1
2
3
4
5
6
7
8
void split (list * splitlist , list * & A, list * & B)
{ Link * curr = splitlist -> first;
   while ( curr != NULL)
    { A->add(A->first ,curr->data);
      curr = curr -> next;
        if ( curr != NULL)
         B-> add(B->first, curr-> data) ;
      curr = curr -> next ; }}
Apr 24, 2014 at 1:31am
I was able to fix this part of the code:
1
2
3
if ( curr != NULL)
{    B-> add(B->first, curr-> data) ;
      curr = curr -> next ; }}}

but now I get really weird error:
terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc
Abort (core dumped)
Apr 24, 2014 at 2:05am
Apr 24, 2014 at 10:00pm
I don't exactly get what the problem is ? or how to fix it ?

Help Plz
Apr 24, 2014 at 10:10pm
Basically, this is the error thrown by ::operator new or ::operator new[] when it can't allocate memory. The three most probable cases for this are either you are allocating more memory than you have, the heap is fragmented enough that you can't allocate enough continuguous memory, or you have done something like trying to allocate an array with a negative size.
Topic archived. No new replies allowed.