avoid 'show_transcient_light()' complaint

The static analyzer complained about use of 'obj' maybe being Null
when used in an impossible warning, but that warning will never
appear for the case where obj is actually Null.  Add an assert()
that should let it figure that out, and move the impossible check
inside the 'else' clause where the check matters.  (Either of those
by itself ought to be adequate to pacify the analyzer.)
This commit is contained in:
PatR
2023-12-15 14:52:53 -08:00
parent 3c421da746
commit bf5b4c40e2

View File

@@ -1,8 +1,9 @@
/* NetHack 3.7 light.c $NHDT-Date: 1657918094 2022/07/15 20:48:14 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.57 $ */
/* NetHack 3.7 light.c $NHDT-Date: 1702680171 2023/12/15 22:42:51 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.66 $ */
/* Copyright (c) Dean Luick, 1994 */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#include <assert.h>
/*
* Mobile light sources.
@@ -239,6 +240,9 @@ show_transient_light(struct obj *obj, coordxy x, coordxy y)
cameraflash = cg.zeroany;
/* radius 0 will just light <x,y>; cameraflash.a_obj is Null */
ls = new_light_core(x, y, 0, LS_OBJECT, &cameraflash);
/* pacify static analysis; 'ls' is never Null for
new_light_core(,,0,LS_OBJECT,&zeroany) */
assert(ls != NULL);
} else {
/* thrown or kicked object which is emitting light; validate its
light source to obtain its radius (for monster sightings) */
@@ -248,12 +252,14 @@ show_transient_light(struct obj *obj, coordxy x, coordxy y)
if (ls->id.a_obj == obj)
break;
}
}
if (!ls || (obj && obj->where != OBJ_FREE)) {
impossible("transient light %s %s is not %s?",
obj->lamplit ? "lit" : "unlit", xname(obj),
!ls ? "a light source" : "free");
return;
assert(obj != NULL); /* necessary condition to get into this 'else' */
if (!ls || obj->where != OBJ_FREE) {
impossible("transient light %s %s %s not %s?",
obj->lamplit ? "lit" : "unlit",
simpleonames(obj), otense(obj, "are"),
!ls ? "a light source" : "free");
return;
}
}
if (obj) /* put lit candle or lamp temporarily on the map */