gcc -fanalyze vs artifact.c

This should pacify the analyzer.  get_artifact(obj) expands to code
which checks whether obj is Null.  untouchable() knows that it will
always be non-Null so didn't perform any comparable test and the
analyzer complained.

Using get_artifact() before the 'beingworn' assignment instead of
after would just have shifted the complaint to the assignment's use
of obj->owornmask.  Adding a test for Null to that expression should
eliminate the complaint but I haven't verified that.
This commit is contained in:
PatR
2023-06-28 07:56:34 -07:00
parent ab0de251cd
commit e44a2a9738

View File

@@ -2304,22 +2304,27 @@ retouch_object(
return 0;
}
/* an item which is worn/wielded or an artifact which conveys
something via being carried or which has an #invoke effect
currently in operation undergoes a touch test; if it fails,
it will be unworn/unwielded and revoked but not dropped */
/* hero has changed form or alignment; an item which is worn/wielded
or an artifact which conveys something via being carried or which
has an #invoke effect currently in operation undergoes a touch test;
if it fails, it will be unworn/unwielded and maybe dropped */
static boolean
untouchable(struct obj *obj, boolean drop_untouchable)
untouchable(
struct obj *obj, /* object to test; in invent or is steed's saddle */
boolean drop_untouchable) /* whether to drop it if it can't be touched */
{
struct artifact *art;
boolean beingworn, carryeffect, invoked;
long wearmask = ~(W_QUIVER | (u.twoweap ? 0L : W_SWAPWEP) | W_BALL);
beingworn = ((obj->owornmask & wearmask) != 0L
/* some items in use don't have any wornmask setting */
|| (obj->oclass == TOOL_CLASS
&& (obj->lamplit || (obj->otyp == LEASH && obj->leashmon)
|| (Is_container(obj) && Has_contents(obj)))));
beingworn = (obj /* never Null; this pacifies static analysis when
* the get_artifact() macro tests 'obj' for Null */
&& ((obj->owornmask & wearmask) != 0L
/* some items in use don't have any wornmask setting */
|| (obj->oclass == TOOL_CLASS
&& (obj->lamplit
|| (obj->otyp == LEASH && obj->leashmon)
|| (Is_container(obj) && Has_contents(obj))))));
if ((art = get_artifact(obj)) != 0) {
carryeffect = (art->cary.adtyp || art->cspfx);
@@ -2346,7 +2351,8 @@ untouchable(struct obj *obj, boolean drop_untouchable)
/* check all items currently in use (mostly worn) for touchability */
void
retouch_equipment(int dropflag) /* 0==don't drop, 1==drop all, 2==drop weapon */
retouch_equipment(
int dropflag) /* 0==don't drop, 1==drop all, 2==drop weapon */
{
static int nesting = 0; /* recursion control */
struct obj *obj;