From 381851348b6647f7a0d5b1b436910039aca7400f Mon Sep 17 00:00:00 2001 From: PatR Date: Fri, 9 Feb 2024 15:48:47 -0800 Subject: [PATCH] fix #K4103 - crash after confused #loot of throne If gold is moved into throne's coffer chest (or added to exchequer monster's minvent) while quivered by the hero, it wasn't being unworn to remove it from quiver slot. That could lead to a crash. Example was segfault during 'f' command. freeinv() expects caller to unwear item being removed from inventory; reverse_loot() wasn't doing so. --- doc/fixes3-7-0.txt | 5 ++++- src/pickup.c | 14 ++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 7fdc7c9da..af7ab5c57 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1368 $ $NHDT-Date: 1706272459 2024/01/26 12:34:19 $ +$NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1376 $ $NHDT-Date: 1707521382 2024/02/09 23:29:42 $ General Fixes and Modified Features ----------------------------------- @@ -1357,6 +1357,9 @@ if loadstone was unIDed but had been assigned a type name and you failed to "stone called " when a vision blocking gas cloud dissipated, the screen didn't necessarily get updated to show newly visible locations in a timely fashion +if confused #loot while on a throne moved whole stack of quivered gold into + 'coffers' chest, the gold wasn't unworn from quiver slot, potentially + leading to crash when quiver was subsequently accessed Fixes to 3.7.0-x General Problems Exposed Via git Repository diff --git a/src/pickup.c b/src/pickup.c index 33af16001..88ad325e5 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 pickup.c $NHDT-Date: 1700012890 2023/11/15 01:48:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.348 $ */ +/* NetHack 3.7 pickup.c $NHDT-Date: 1707521383 2024/02/09 23:29:43 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.370 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2334,8 +2334,7 @@ reverse_loot(void) int n, x = u.ux, y = u.uy; if (!rn2(3)) { - /* n objects: 1/(n+1) chance per object plus 1/(n+1) to fall off end - */ + /* n objects: 1/(n+1) chance per object, 1/(n+1) to fall off end */ for (n = inv_cnt(TRUE), otmp = gi.invent; otmp; --n, otmp = otmp->nobj) if (!rn2(n + 1)) { prinv("You find old loot:", otmp, 0L); @@ -2355,6 +2354,10 @@ reverse_loot(void) if (!goldob) return FALSE; + /* gold might be quivered; dropping would un-wear it, but freeinv() + expects caller to do that; do so now */ + remove_worn_item(goldob, FALSE); + if (!IS_THRONE(levl[x][y].typ)) { dropx(goldob); /* the dropped gold might have fallen to lower level */ @@ -2367,9 +2370,8 @@ reverse_loot(void) if (coffers->otyp == CHEST) { if (coffers->spe == 2) break; /* a throne room chest */ - if (!otmp - || (distu(coffers->ox, coffers->oy) - < distu(otmp->ox, otmp->oy))) + if (!otmp || (distu(coffers->ox, coffers->oy) + < distu(otmp->ox, otmp->oy))) otmp = coffers; /* remember closest ordinary chest */ } if (!coffers)