From 3bc8af983647a618d714264b071945a38faf90f0 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 24 Dec 2023 14:47:08 -0500 Subject: [PATCH] static analyzer bit for wield.c src/wield.c(254): warning: Dereferencing NULL pointer 'wep'. See line 190 for an earlier location where this can occur This seems to be a case where an unnecessary null test (A) caused the analyzer to call into question whether or not wep is null at (B): if (!wep) { } else if (wep->otyp == CORPSE && cant_wield_corpse(wep)) { } else if (uarms && bimanual(wep)) { } else if (!retouch_object(&wep, FALSE)) { } else { /* Weapon WILL be wielded after this point */ if (will_weld(wep)) { } else { } if (was_twoweap && !u.twoweap && flags.verbose) { } /* KMH -- Talking artifacts are finally implemented */ A ==> if (wep && wep->oartifact) { } if (artifact_light(wep) && !wep->lamplit) { } B ==> if (wep->unpaid) { } } Removing the extraneous wep test from (A) resolves the complaint. --- src/wield.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wield.c b/src/wield.c index f06215117..11565e3bf 100644 --- a/src/wield.c +++ b/src/wield.c @@ -232,7 +232,7 @@ ready_weapon(struct obj *wep) } /* KMH -- Talking artifacts are finally implemented */ - if (wep && wep->oartifact) { + if (wep->oartifact) { res |= arti_speak(wep); /* sets ECMD_TIME bit if artifact speaks */ }