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 added brackets based on the indentions, in order to not
> get ambiguous else statements when compiling.

Personally, I would much rather have ambiguous else warnings than
incorrect code.  (I would fix the warnings, but do it in such a way
as to not change the logic of the code).

>     case TAR_OBJ_CHAR_OFF:
>         if ( victim == NULL && obj == NULL)
>       {       <-- Added this so the compiler didn't complain.
>           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;
>           }
>       }  <-- Added this so the compiler didn't complain.
>         break;
>
>
> See how "something" is misspelled?  Haha, what a horrible bug!  Just
> kidding.  Seriously though, it offers no else statement for if ( victim ==
> NULL && obj == NULL).

Yes it does.  2/3 of the code you posted does exactly that!

> I added as an alternative (a la TAR_OBJ_CHAR_DEF):
>       else if (victim != NULL)
>       {
>           vo = (void *) victim;
>           target = TARGET_CHAR;
>       }
>       else
>       {
>           vo = (void *) obj;
>           target = TARGET_OBJ;
>       }

If you'd look at the stock code, you would see that this was already there,
at least before you got ahold of it.

> I'm no longer able to crash the mud when reciting a scroll of curse on an
> object, and my pills of curse work as well.  I can still manually cast on
> myself, on others, and on objects.  Does anyone see anything wrong with
> this, and is this in fact a bug?

This was in fact a bug.  Not in the stock code, but in your modification
of the stock code.

> I'm simply helping with this mud, and there have been tons of changes
> that may have "broken" it.

Such as completely changing the logic of the stock code in question...

> Thanks,
>
> Jimmy


if ( a )                                 if ( a )
  if ( b )                               {
    i = 1;                                 if ( b )
                                             i = 1;
  j = 2;
                                           j = 2;
                                         }

Notice the difference in these two versions?  If not, go get out your
C book and read through it until you figure it out.


Dennis



Reply via email to