[CODE] Arena affections crash

From: Melissa Jadwinski (meersan@earthlink.net)
Date: 08/31/00


Lately I've been working on writing arena code for my mud.  However,
I've hit a snag in the form of an irritating crash bug which I haven't
been able to track down.  I've been staring at the place where it
crashes and the code still makes sense to *me* -- why doesn't it make
sense to the mud?

The crash occurs in a function called arena_store_affects().  That's
where I attempt to remove the affects from a character, and store
them for later.  (That way players enter the arena without spell-ups,
and get them back when they exit.)


The code....
struct combatant_info_type {
  struct char_data *ch;             /* player                          */
  sh_int was_in;                    /* room was in                     */
  byte team;                        /* which team it's on              */
  sh_int hit;                       /* maxhit/mana/moves               */
  sh_int mana;
  sh_int move;
  struct affected_type *affected;   /* affects that were on the player */
  struct combatant_info_type *next; /* the next combatant              */
};

void arena_store_affects(struct char_data *ch, struct combatant_info_type
*comb) {
  struct affected_type *aff, *new_aff;

  comb->affected = NULL;

  for (aff = ch->affected; aff; aff = aff->next) {
    CREATE(new_aff, struct affected_type, 1);
    clear_affect(new_aff);

    new_aff->type       = aff->type;  /* <-- Crashes here */
    new_aff->idnum      = aff->idnum;
    new_aff->duration   = aff->duration;
    new_aff->modifier   = aff->modifier;
    new_aff->location   = aff->location;
    new_aff->bitvector  = aff->bitvector;
    new_aff->bitvector1 = aff->bitvector1;

    new_aff->next = comb->affected;
    comb->affected = new_aff;

    affect_remove(ch, aff);

  }

}

GDB says...

Core was generated by `bin/circle -q 4200'.
Program terminated with signal 11, Segmentation fault.

#0  arena_store_affects (ch=0x874d478, comb=0x8750e70) at arena.c:207
207         new_aff->type       = aff->type;
(gdb) bt
#0  arena_store_affects (ch=0x874d478, comb=0x8750e70) at arena.c:207
#1  0x808fbba in add_combatant (ch=0x874d478, team=0) at arena.c:129
#2  0x8090fd0 in arena_join (ch=0x874d478) at arena.c:953
#3  0x8090b12 in do_arena (ch=0x874d478, argument=0xbffffa8d " accept",
cmd=28, subcmd=0) at arena.c:709
#4  0x80bccb6 in command_interpreter (ch=0x874d478, argument=0xbffffa88
"arena accept") at interpreter.c:954
#5  0x804a33c in game_loop (mother_desc=3) at comm.c:782
#6  0x8049a64 in init_game (port=4200) at comm.c:384
#7  0x80499d9 in main (argc=3, argv=0xbffffde8) at comm.c:346
(gdb) printf "new_aff->type: %d, aff->type: %d\n", new_aff->type, aff->type
new_aff->type: 0, aff->type: 8305
(gdb) print new_aff
$1 = (struct affected_type *) 0x874ed20
(gdb) print aff
$2 = (struct affected_type *) 0x38
(gdb) print *aff
$3 = {type = 8305, duration = 12852, modifier = 48 '0', location = 48 '0',
idnum = 0, bitvector = 0, bitvector1 = 0,
  bitvector2 = 0, bitvector3 = 0, bitvector4 = 0, bitvector5 = 0, demon_id
= 0, obj_bitvector = 0, room_bitvector = 0,
  next = 0x0}

It looks like 'aff' is total garbage, but I don't know how that is
happening.  I tried putting in a couple log statements, but the mud
crashed on _them_.  Maybe it's because I've been coding for 17 hours
straight, but I can't see what I'm missing.

The log...

< 5000H 5000M 1000V > cast 'spellshield' me
Okay.
A shield of magical energy surrounds your body.

< 5000H 5000M 1000V > stat meer
female PC 'Meer'  IDNum: [    1], In room [ 1214]
L-Des: <None>
Level: [110], XP: [50000000], Align: [-110], Remorts: [0]
Created: [Mon Feb 28], Last Logon: [Thu Aug 31], Played [0h 0m], Age [31]
Hometown: [1], Speaks: [0/0/0], Pracs: [99], Has Remort: no(0)
Hit Pts:[5000/5000+10]  Mana Pts:[5000/5000+24]  Move Pts:[1000/1000+24]
Coins: [        0], Bank: [    37805] (Total: 37805)
AC: [0], Hitroll: [ 3], Damroll: [ 0]
Saving throws: [20/0/0/0/0/0/0/0/0/0/0/0]
Pos: Standing, Fighting: Nobody, Connected: Playing
Default position: Standing, Idle Timer (in tics) [0]
PLR: NOBITS
PRF: D_H D_M D_V A_EX !HASS LIGHT C1 C2 L1 L2 RMFLG A_COND STACK
Carried: weight: 0, items: 0; Items in: inventory: 0, eq: 0
Hunger: [-1], Thirst: [-1], Drunk: [-1], Drugged: [-1]
Master is: <none>, Followers are:
AFF : NOBITS
AFF1: SPELLSHIELD
SPL: (  7hr) spellshield           +20 to SAVE_MAGIC

< 5000H 5000M 1000V >
[ARENA] Lyre challenges Meer to a duel!
[ARENA] You have been challenged to a duel by Lyre!  (Type 'arena accept'
to defend your honor.)

< 5000H 5000M 1000V > arena accept
[BOOM!!!]


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/11/01 PDT