for (paf = first_ob->pIndexData->first_affect; paf; paf = paf->next) {
ch_printf_color( ch, "&cAffects &w%s &cby &w%d.\r\n", affect_loc_name( paf->location ), paf->modifier );
UNLINK( paf, first_ob->pIndexData->first_affect, first_ob->pIndexData->last_affect, next, prev);
paf->duration = -1;
LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );
}
The first line assumes that paf is a member of the linked list proceeding from first_ob->pIndexData->first_affect.
The UNLINK statement invalidates that.
After the LINK statement at the end of the block, paf is a member of the list proceeding from second_ob->first_affect and the iteration step (paf = paf->next) sets paf to the next object in the second_ob->first_affect list.
To get around that you need to cache the value of paf->next:
AFFECT_DATA *paf_next; /* or whatever paf is declared as */
for (paf = first_ob->pIndexData->first_affect; paf; paf = paf_next) {
paf_next = paf->next;
ch_printf_color( ch, "&cAffects &w%s &cby &w%d.\r\n", affect_loc_name( paf->location ), paf->modifier );
UNLINK( paf, first_ob->pIndexData->first_affect, first_ob->pIndexData->last_affect, next, prev);
paf->duration = -1;
LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );
}
As a side note, (and it's been a while since I had to write portable C), can't the second section be rewritten as something like:
char **sdescs[6] = { &(second_ob->sdesc1), &(second_ob->sdesc2), &(second_ob->sdesc3), &(second_ob->sdesc4), &(second_ob->sdesc5), &(second_ob->sdesc6) };
short i = 0;
for (; i < 6; ++i) {
if (*(sdescs[ i ]) == NULL || (*(sdescs[ i ]))[0] == '\0') {
STRFREE(*(sdescs[ i ]));
*(sdescs[ i ]) = STRALLOC( buf1 );
break;
}
}
|