From 79496b079a87691c2883965f3865709ace425a57 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 21 Oct 2023 19:41:17 +0300 Subject: [PATCH] Fix splitting monster being killed twice Fuzzer encountered "m_detach: monster already detached?" A monster hit a black pudding that split. The clone was created on top of a rolling boulder trap, which triggered, the boulder hit the original black pudding, and killed it. The dead pudding then retaliated (as the code didn't check if it was dead) and a passive attack of the other monster tried to kill the already dead pudding. I think one of these checks would be enough, but adding the DEADMONSTER check just in case. --- src/mhitm.c | 2 ++ src/monmove.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mhitm.c b/src/mhitm.c index 33d8af026..17e55bdcd 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -454,6 +454,8 @@ mattackm( pline("%s divides as %s hits it!", Monnam(mdef), mon_nam(magr)); (void) mintrap(mclone, NO_TRAP_FLAGS); + if (DEADMONSTER(magr)) + res[i] |= M_ATTK_AGR_DIED; } } } else diff --git a/src/monmove.c b/src/monmove.c index be38cf48d..c46494702 100644 --- a/src/monmove.c +++ b/src/monmove.c @@ -1892,7 +1892,7 @@ m_move_aggress(struct monst *mtmp, coordxy x, coordxy y) mstatus = mattackm(mtmp, mtmp2); } - if (mstatus & M_ATTK_AGR_DIED) /* aggressor died */ + if ((mstatus & M_ATTK_AGR_DIED) || DEADMONSTER(mtmp)) /* aggressor died */ return MMOVE_DIED; if ((mstatus & (M_ATTK_HIT | M_ATTK_DEF_DIED)) == M_ATTK_HIT