Re: Extraction Crash

From: Chris Proctor (cjp@YOYO.CC.MONASH.EDU.AU)
Date: 10/20/97


> >>> > Well, the best I can offer is that you do not test for
> >>> > the null condition of temp->next.  Thus you are probably
> >>> > seg faulting here. Try:
> >>> >  while (temp && temp->next && (temp->next != obj))
> >>> >
> >>> > Not sure this is it, but its a good idea to always check
> >>> > for the NULL condition anyway.
> >>
> >>I tried that as well. As soon as I try to access temp->next in ANY form,
> >>the crash hits with a seg fault. :(
>
> There was quite a bit of discussion a long time ago
> about using <struct>->next in loop conditions.
> If I remember correctly, it could all be summarized with:
> don't do it.
>
> Do something instead like:
> while (temp && next_temp && (next_temp != obj)) {
>     next_temp = temp->next;
>     etc.
> }

You might want to make sure that none of the functions called in your
loop body do a free() of the structure.

I had a similar problem, and it was because the structure I was
manipulating was freed halfway through. Not good ;-)

Chris

_____________________________________________________
      "A double-edged sword lets you cut down
      your enemies with the backswing as well."
             -- Gerrard of the Weatherlight
-----------------------------------------------------
     Check out Dominia Mud, on snafu.net.au 3333
  Or my homepage: http://yoyo.cc.monash.edu.au/~cjp


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST