fix github issue #1252 - current HP > maximum HP
Sanity check failure generated by running the fuzzer, reported
by mkuoppal. The check discovered that the hero's current hit
points were greater than the maximum.
Comments by elunna pointed out where the problem most likely was,
and this attempts to fix the situation, but without a test case
I can't be sure that the fix works.
Both cases being fixed are for formerly fatal incidents (random
chance that poison is fatal, monster touch of death spell) being
'softened' to heavy HP damage (including reduction of maxHP).
The earlier commit I made (045d608) was done without having seen
the relevant comments. It didn't fix anything but did attempt
to make finding the problem(s) easier. It wasn't much help.
Fixes #1252
This commit is contained in:
15
src/mcastu.c
15
src/mcastu.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 mcastu.c $NHDT-Date: 1705428596 2024/01/16 18:09:56 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.95 $ */
|
||||
/* NetHack 3.7 mcastu.c $NHDT-Date: 1726168598 2024/09/12 19:16:38 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.105 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Robert Patrick Rankin, 2011. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -390,7 +390,18 @@ touch_of_death(struct monst *mtmp)
|
||||
Strcpy(svk.killer.name, kbuf);
|
||||
done(DIED);
|
||||
} else {
|
||||
u.uhpmax -= drain;
|
||||
/* HP manipulation similar to poisoned(attrib.c) */
|
||||
int olduhp = u.uhp,
|
||||
newuhpmax = u.uhpmax - drain;
|
||||
|
||||
setuhpmax(max(newuhpmax, minuhpmax(3)));
|
||||
/* reduce pending loss if uhp has already been reduced due to
|
||||
drop in uhpmax */
|
||||
if (u.uhp < olduhp) {
|
||||
dmg -= (olduhp - u.uhp);
|
||||
if (dmg < 1)
|
||||
dmg = 1;
|
||||
}
|
||||
losehp(dmg, kbuf, KILLED_BY);
|
||||
}
|
||||
svk.killer.name[0] = '\0'; /* not killed if we get here... */
|
||||
|
||||
Reference in New Issue
Block a user