static analyzer changes for trap.c

Picked arbitrarily; there weren't any unresolved analyzer complaints
for trap.c.  I wonder why the onefile analysis isn't complaining here.

'in_sight' may have been relevant before the trapeffect_xyz() code
was split apart, but it isn't useful for trapeffect_hole() despite
the comment about it.

release_holding_trap() is fairly convoluted and the complaints being
addressed here were relevant.
This commit is contained in:
PatR
2025-01-17 21:26:32 -08:00
parent e48824223f
commit 34dc5d7acf

View File

@@ -2028,8 +2028,6 @@ trapeffect_hole(
if (in_sight) {
pline_mon(mtmp,
"%s seems to be yanked down!", Monnam(mtmp));
/* suppress message in mlevel_tele_trap() */
in_sight = FALSE;
seetrap(trap);
}
} else
@@ -6003,7 +6001,7 @@ openholdingtrap(
boolean *noticed) /* set to true iff hero notices the effect;
* otherwise left with its previous value intact */
{
struct trap *t;
struct trap *t, tdummy;
char buf[BUFSZ], whichbuf[20];
const char *trapdescr = 0, *which = 0;
boolean ishero = (mon == &gy.youmonst);
@@ -6016,7 +6014,15 @@ openholdingtrap(
t = t_at(ishero ? u.ux : mon->mx, ishero ? u.uy : mon->my);
if (ishero && u.utrap) { /* all u.utraptype values are holding traps */
/* there might not be any trap at hero's spot for tt_buriedball;
conversely, there might be an unrelated trap at that spot */
if (!t) {
t = &tdummy;
(void) memset(t, 0, sizeof *t), t->ntrap = NULL;
/* fallback 't' is now nonNull, t->tseen and t->madeby_u are 0 */
}
which = the_your[(!t || !t->tseen || !t->madeby_u) ? 0 : 1];
switch (u.utraptype) {
case TT_LAVA:
trapdescr = "molten lava";
@@ -6032,7 +6038,9 @@ openholdingtrap(
case TT_BEARTRAP:
case TT_PIT:
case TT_WEB:
trapdescr = 0; /* use defsyms[].explanation */
trapdescr = defsyms[(u.utraptype == TT_WEB) ? S_web
: (u.utraptype == TT_PIT) ? S_pit
: S_bear_trap].explanation;
break;
default:
/* lint suppression in case 't' is unexpectedly Null
@@ -6044,10 +6052,9 @@ openholdingtrap(
/* if no trap here or it's not a holding trap, we're done */
if (!t || (t->ttyp != BEAR_TRAP && t->ttyp != WEB))
return FALSE;
}
if (!trapdescr)
trapdescr = trapname(t->ttyp, FALSE);
}
assert(t != NULL);
if (!which)
which = t->tseen ? the_your[t->madeby_u]
: strchr(vowels, *trapdescr) ? "an" : "a";