Re: [Circle] newbie fighting question

From: Charles Canning (charles@engr.mun.ca)
Date: 07/29/96


Hi,

I was just wondering why this is considered safer? I see no difference in 
the two. Both will crash if i = NULL. So what's up? Or am I completely 
off my rocker this evening.

Later...
...Chuck

On Sun, 28 Jul 1996, Niese-Petersen wrote:

> On Sun, 28 Jul 1996 goamkows@kirk.geog.scarolina.edu wrote:
> 
> This is not an answer to the question, but a warning for a common
> bug....
> 
> >     for (i = world[ch->in_room].people; i; i = i->next_in_room)
>                                                  ^^^^^^^^^^^^^^^
>                                                         |
>   This is dangerous. Special since 'i' has a chance for dying.
> If 'i' die, then 'i->next_in_room' is NULL or something weird, since
> 'i' is being extracted..
> 
>   what to do instead:
> 
> Add a struct char_data *next_i;
> 
> for (i = world[ch->in_room; i; i = next_i) {
>   next_i = i->next_in_room;
> ...etc...
> 
> 
> ---
> Erik Niese-Petersen
> Aka Quint The typo God
> Realms of Darkness IMP [matrix.xiii.com 6666. Playertesting]
> 
> 
> +-----------------------------------------------------------+
> | Ensure that you have read the CircleMUD Mailing List FAQ: |
> |   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
> +-----------------------------------------------------------+
> 
+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



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