From e5504367550ecb906f6f06f8479c2b78b1ad6190 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 30 Jul 2024 11:52:34 -0700 Subject: [PATCH] shapechanger crash fix A recent change was setting mon->data prior to canspotmon(mon) but that triggered a crash if the temporary mon->data was Null. All the testing was done with vampshifers and this affects non-vampshifers. Push even more shapechange messaging into newcham() by not trying to determine whether requesting a message from it will oblige. --- src/mon.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/mon.c b/src/mon.c index 97a7faed5..b11b6cdf3 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 mon.c $NHDT-Date: 1722116051 2024/07/27 21:34:11 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.583 $ */ +/* NetHack 3.7 mon.c $NHDT-Date: 1722365546 2024/07/30 18:52:26 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.584 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -4669,7 +4669,7 @@ decide_to_shapeshift(struct monst *mon) boolean dochng = FALSE; if (!is_vampshifter(mon)) { - /* regular shapeshifter */ + /* regular shapeshifter; 'ptr' is Null */ if (!rn2(6)) dochng = TRUE; } else if (!(mon->mstrategy & STRAT_WAITFORU)) { @@ -4715,20 +4715,7 @@ decide_to_shapeshift(struct monst *mon) } } if (dochng) { - unsigned ncflags = (is_vampshifter(mon) || canspotmon(mon)) - ? NC_SHOW_MSG : 0U; - - if (!ncflags) { - /* cheat */ - struct permonst *oldptr = mon->data; - - mon->data = ptr; - if (canspotmon(mon)) - ncflags = NC_SHOW_MSG; - mon->data = oldptr; - } - - if (newcham(mon, ptr, ncflags)) { + if (newcham(mon, ptr, NC_SHOW_MSG)) { /* for vampshift, override the 10% chance for sex change (by forcing original gender in case that occurred) */ if (is_vampshifter(mon)) {