From 7c0cb78bbf493af575d13182f6bd283e20203c98 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 6 Feb 2010 18:11:23 +0000 Subject: [PATCH] fix crash when items disappear --- src/common/kernel/battle.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index ac3de1e2e..b7a4b5518 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -1364,11 +1364,17 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) fprintf(bdebug, "Damage %d, armor %d, type %d: %d -> %d HP, tot.\n", da, ar, type, df->person[dt.index].hp + rda, df->person[dt.index].hp); } - for (pitm=&du->items; *pitm; pitm=&(*pitm)->next) { - const item_type * itype = (*pitm)->type; - if (!(itype->flags & ITF_CURSED) && dt.index < (*pitm)->number) { + for (pitm=&du->items; *pitm; ) { + item * itm = *pitm; + const item_type * itype = itm->type; + if (!(itype->flags & ITF_CURSED) && dt.index < itm->number) { /* 25% Grundchance, das ein Item kaputtgeht. */ - if (rng_int() % 4 < 1) i_change(pitm, itype, -1); + if (rng_int() % 4 < 1) { + i_change(pitm, itype, -1); + } + } + if (*pitm==itm) { + pitm = &itm->next; } } kill_troop(dt);