Segmentation fault

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 ; }}
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)
I don't exactly get what the problem is ? or how to fix it ?

Help Plz
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.