New problem, any information would be good

Posted by Trom on Thu 08 Apr 2004 07:09 AM — 4 posts, 17,632 views.

#0
Now i've been posting a lot in this forum the last few months. The only probs i bring up here is ones i can't figure out after trying for at least a day. Now most errors in gdb seem to be segmentation fault or something like that. But this one is new.

Program received signal SIGFPE, Arithmetic exception.
0x00499216 in new_saves_spell (ch=0xdbed88, victim=0xdbed88, dam_type=9)
at magic.c:229
229 save = ( (vic_save * 100) / (ch_save + vic_save) );


The problem occurs when, as a mortal i try to cast curse on myself (some people might try that) and it crashes the mud. In gdb it gives the above error "arithmetic exception". I've re-arranged the formula, checked the values of vic_save, ch_save, ch, victim, and its all done correctly... I just don't get why this error would come up. I've even made the values into variable then did the division, still the same prob.



Backtrace shows this:
(gdb) bt
#0 0x00499216 in new_saves_spell (ch=0xdbed88, victim=0xdbed88, dam_type=9)
at magic.c:229
#1 0x0049deb5 in spell_curse (sn=60, level=129, ch=0xdbed88, vo=0xdbed88,
target=0) at magic.c:1922
#2 0x0049a7e1 in do_cast (ch=0xdbed88, argument=0xdbe0a2 "curse self")
at magic.c:780
#3 0x00497c8c in interpret (ch=0xdbed88, argument=0xdbe09d "cast curse self")
at interp.c:669
#4 0x0044144c in substitute_alias (d=0xdbd720,
argument=0xdbe09d "cast curse self") at alias.c:107
#5 0x00449bdb in game_loop_unix (control=4, wwwcontrol=5) at comm.c:905
#6 0x00449478 in main (argc=1, argv=0xb113b0) at comm.c:472


#1
This is the problem function (not sure why its a prob):

bool new_saves_spell ( CHAR_DATA * ch, CHAR_DATA * victim, int dam_type )
{
int save = 0, vic_save = 0, ch_save = 0;

ch_save = IS_NPC(ch) ? ch->level/20 : ch->pcdata->saves;
vic_save = IS_NPC(victim) ? victim->level/20 : victim->pcdata->saves;

// if the victim of the saving throw is berserked, they can't defend as well
if ( IS_AFFECTED ( victim, AFF_BERSERK ) )
vic_save -= 2;

switch ( check_immune ( victim, dam_type ) )
{
case IS_IMMUNE:
return TRUE;
case IS_RESISTANT:
vic_save += 8;
break;
case IS_VULNERABLE:
vic_save -= 8;
break;
}

save = ( (vic_save * 100) / (ch_save + vic_save) );

return number_percent() < save;
}
Amended on Thu 08 Apr 2004 07:13 AM by Trom
Australia Forum Administrator #2
What is ch_save + vic_save equal to? Zero? You might be dividing by zero.

Check that out in gdb. When you get the exception type:

print ch_save + vic_save
#3
Thanks, that was the problem. The base saves were 0, forgot that can be a problem in division. Thanks