From ffc43610f03aa35cfc5c18f87143ee225f33339f Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 22 Jan 2025 16:34:05 -0800 Subject: [PATCH] analysis lint for u*.c One actual bug: mhitm_ad_ench() could pass Null to drain_item() which was not prepared to deal with that. --- src/u_init.c | 3 ++- src/uhitm.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/u_init.c b/src/u_init.c index 58040518f..1d0913f80 100644 --- a/src/u_init.c +++ b/src/u_init.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 u_init.c $NHDT-Date: 1725227809 2024/09/01 21:56:49 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.111 $ */ +/* NetHack 3.7 u_init.c $NHDT-Date: 1737620595 2025/01/23 00:23:15 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.113 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2017. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1329,6 +1329,7 @@ ini_inv(struct trobj *trop) * it was UNDEF_TYP or not after this. */ otyp = ini_inv_obj_substitution(trop, obj); + nhUse(otyp); /* nudist gets no armor */ if (u.uroleplay.nudist && obj->oclass == ARMOR_CLASS) { diff --git a/src/uhitm.c b/src/uhitm.c index dc7264af1..d40f712c0 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -1813,8 +1813,10 @@ hmon_hitmon( hmon_hitmon_msg_hit(&hmd, mon, obj); - if (hmd.dryit) /* dryit implies wet towel, so 'obj' is still intact */ + if (hmd.dryit) { /* dryit implies wet towel, so 'obj' is still intact */ + assert(obj != NULL); dry_a_towel(obj, -1, TRUE); + } if (hmd.silvermsg) hmon_hitmon_msg_silver(&hmd, mon, obj); @@ -1826,8 +1828,10 @@ hmon_hitmon( obj->opoisoned was cleared above and any message referring to "poisoned " has now been given; we want just "" for last message, so reformat while obj is still accessible */ - if (hmd.unpoisonmsg) + if (hmd.unpoisonmsg) { + assert(obj != NULL); Strcpy(hmd.saved_oname, cxname(obj)); + } /* [note: thrown obj might go away during killed()/xkilled() call (via 'thrownobj'; if swallowed, it gets added to engulfer's @@ -3508,6 +3512,7 @@ mhitm_ad_slim( mhm->damage = 0; } } + nhUse(pd); } void @@ -3549,7 +3554,7 @@ mhitm_ad_ench( break; } } - if (drain_item(obj, FALSE)) { + if (obj && drain_item(obj, FALSE)) { pline("%s less effective.", Yobjnam2(obj, "seem")); } }