Re: Extraction Crash <c=US%a=_%p=MATHINC%l=MPR5-971020192105Z-75960@mpr5.MATHINC>

From: Jeremy Elson (jelson@CIRCLEMUD.ORG)
Date: 10/20/97

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

The dangerous code is something like:

for (ch = character_list; ch; ch = ch->next) {

If do_some_bad_stuff() is bad, e.g. can possibly kill ch.  If ch dies,
he is immediately extracted and freed (if a MOB), causing a segfault
when the (now invalid) ch is dereferenced at the statement (ch =
ch->next).  This is the reason for the common construct found
througout the code:

for (ch = character_list; ch; ch = next_ch) {
  next_ch = ch->next;

I didn't see the original post on this topic, but this type of error
might be why you're getting segfaults when trying to extract
something.  Make sure you save a copy of the obj->next pointer before
trying to do anything to obj (especially extracting obj, which
free()'s it!)


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

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