On Mon, 1 Apr 2002, Dennis wrote:
> On Mon, 1 Apr 2002, Anarchangel wrote:
>
> > Hello everyone,
> >
> > Every couple of weeks or so we'll crash with a problem in curse. Usually
> > the problem is vo is NULL. It always happened when curse was either an
> > affect that would be added after eating a pill, or when a scroll of curse
> > was recited on an object. In trying to squash this bug, I may have found
> > a problem in obj_cast_spell. Attached is the stock problematic(?) portion
> > of the code.
>
> Wrong. Attached is your version of the code. It is no longer the stock
> code, or even logically equivalent to it.
I'm going to have to disagree here. Take a look at the stock code.
if ( victim == NULL && obj == NULL)
if (ch->fighting != NULL)
victim = ch->fighting;
else
{
send_to_char("You can't do that.\n\r",ch);
return;
}
if (victim != NULL)
{
if (is_safe_spell(ch,victim,FALSE) && ch != victim)
{
send_to_char("Somehting isn't right...\n\r",ch);
return;
}
vo = (void *) victim;
target = TARGET_CHAR;
}
else
{
vo = (void *) obj;
target = TARGET_OBJ;
}
break;
Take a look at those indentions. The first line, if ( victim == NULL &&
obj == NULL) lines up with only one thing, the break
statement. The other else's are, therefore, meant to be else statements
for if (ch->fighting != NULL). Notice how they line up.
Yes, I realize that the original intent of the code was to make else
conditions for the first line. But it's written (or formatted, I should
say) in such a way that it leads the reader to believe otherwise.
<snip code>
if ( a ) if ( a )
if ( b ) {
i = 1; if ( b )
i = 1;
j = 2;
j = 2;
}
Nice example. I was going to use the same one for you.
Jimmy