warning suppression

Fix a couple of the clang static analyzer's warnings.

muse.c has some reformatting.  zap.c wasn't triggering any warning about
possible null pointer, but using MON_AT() to maybe avoid m_at() is not
a useful optimization since m_at() is a macro which starts out by using
MON_AT() itself.
This commit is contained in:
PatR
2015-11-19 18:49:50 -08:00
parent 7d23420314
commit a2a567737e
3 changed files with 44 additions and 42 deletions

View File

@@ -1,5 +1,5 @@
/* NetHack 3.6 muse.c $NHDT-Date: 1445556877 2015/10/22 23:34:37 $ $NHDT-Branch: master $:$NHDT-Revision: 1.66 $ */ /* NetHack 3.6 muse.c $NHDT-Date: 1447987786 2015/11/20 02:49:46 $ $NHDT-Branch: master $:$NHDT-Revision: 1.68 $ */
/* Copyright (C) 1990 by Ken Arromdee */ /* Copyright (C) 1990 by Ken Arromdee */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
/* /*
@@ -24,17 +24,17 @@ STATIC_DCL void FDECL(mzapmsg, (struct monst *, struct obj *, BOOLEAN_P));
STATIC_DCL void FDECL(mreadmsg, (struct monst *, struct obj *)); STATIC_DCL void FDECL(mreadmsg, (struct monst *, struct obj *));
STATIC_DCL void FDECL(mquaffmsg, (struct monst *, struct obj *)); STATIC_DCL void FDECL(mquaffmsg, (struct monst *, struct obj *));
STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *)); STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *));
STATIC_DCL void FDECL(mbhit, STATIC_DCL void FDECL(mbhit, (struct monst *, int,
(struct monst *, int, int FDECL((*), (MONST_P, OBJ_P)), int FDECL((*), (MONST_P, OBJ_P)),
int FDECL((*), (OBJ_P, OBJ_P)), struct obj *)); int FDECL((*), (OBJ_P, OBJ_P)), struct obj *));
STATIC_DCL void FDECL(you_aggravate, (struct monst *)); STATIC_DCL void FDECL(you_aggravate, (struct monst *));
STATIC_DCL void FDECL(mon_consume_unstone, STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *, struct obj *,
(struct monst *, struct obj *, BOOLEAN_P, BOOLEAN_P)); BOOLEAN_P, BOOLEAN_P));
STATIC_DCL boolean STATIC_DCL boolean FDECL(cures_stoning, (struct monst *, struct obj *,
FDECL(cures_stoning, (struct monst *, struct obj *, BOOLEAN_P)); BOOLEAN_P));
STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *)); STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *));
STATIC_DCL boolean STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *,
FDECL(muse_unslime, (struct monst *, struct obj *, BOOLEAN_P)); BOOLEAN_P));
STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *)); STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *));
STATIC_DCL boolean FDECL(green_mon, (struct monst *)); STATIC_DCL boolean FDECL(green_mon, (struct monst *));
@@ -48,17 +48,16 @@ static struct musable {
*/ */
} m; } m;
static int trapx, trapy; static int trapx, trapy;
static boolean zap_oseen; static boolean zap_oseen; /* for wands which use mbhitm and are zapped at
/* for wands which use mbhitm and are zapped at players. We usually * players. We usually want an oseen local to
* want an oseen local to the function, but this is impossible since the * the function, but this is impossible since the
* function mbhitm has to be compatible with the normal zap routines, * function mbhitm has to be compatible with the
* and those routines don't remember who zapped the wand. * normal zap routines, and those routines don't
*/ * remember who zapped the wand. */
/* Any preliminary checks which may result in the monster being unable to use /* Any preliminary checks which may result in the monster being unable to use
* the item. Returns 0 if nothing happened, 2 if the monster can't do * the item. Returns 0 if nothing happened, 2 if the monster can't do
* anything * anything (i.e. it teleported) and 1 if it's dead.
* (i.e. it teleported) and 1 if it's dead.
*/ */
STATIC_OVL int STATIC_OVL int
precheck(mon, obj) precheck(mon, obj)
@@ -93,12 +92,11 @@ struct obj *obj;
if (vis) { if (vis) {
pline( pline(
"As %s opens the bottle, an enormous %s emerges!", "As %s opens the bottle, an enormous %s emerges!",
mon_nam(mon), mon_nam(mon),
Hallucination ? rndmonnam(NULL) Hallucination ? rndmonnam(NULL)
: (const char *) "ghost"); : (const char *) "ghost");
pline( pline("%s is frightened to death, and unable to move.",
"%s is frightened to death, and unable to move.", Monnam(mon));
Monnam(mon));
} }
paralyze_monst(mon, 3); paralyze_monst(mon, 3);
} }
@@ -1312,8 +1310,7 @@ struct obj *obj; /* 2nd arg to fhitm/fhito */
if (bhitpos.x == u.ux && bhitpos.y == u.uy) { if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
(*fhitm)(&youmonst, obj); (*fhitm)(&youmonst, obj);
range -= 3; range -= 3;
} else if (MON_AT(bhitpos.x, bhitpos.y)) { } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
mtmp = m_at(bhitpos.x, bhitpos.y);
if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)) if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp))
map_invisible(bhitpos.x, bhitpos.y); map_invisible(bhitpos.x, bhitpos.y);
(*fhitm)(mtmp, obj); (*fhitm)(mtmp, obj);

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 read.c $NHDT-Date: 1446854233 2015/11/06 23:57:13 $ $NHDT-Branch: master $:$NHDT-Revision: 1.121 $ */ /* NetHack 3.6 read.c $NHDT-Date: 1447987787 2015/11/20 02:49:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.123 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -739,17 +739,20 @@ int percent;
return; return;
} }
indices[0] = 0; /* lint suppression */
for (count = 0, i = 1; i < NUM_OBJECTS; i++) for (count = 0, i = 1; i < NUM_OBJECTS; i++)
if (OBJ_DESCR(objects[i]) if (OBJ_DESCR(objects[i])
&& (objects[i].oc_name_known || objects[i].oc_uname)) && (objects[i].oc_name_known || objects[i].oc_uname))
indices[count++] = i; indices[count++] = i;
randomize(indices, count); if (count > 0) {
randomize(indices, count);
/* forget first % of randomized indices */ /* forget first % of randomized indices */
count = ((count * percent) + rn2(100)) / 100; count = ((count * percent) + rn2(100)) / 100;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
forget_single_object(indices[i]); forget_single_object(indices[i]);
}
} }
/* Forget some or all of map (depends on parameters). */ /* Forget some or all of map (depends on parameters). */
@@ -815,6 +818,7 @@ int percent;
* shift the forgetting elsewhere by fiddling with percent * shift the forgetting elsewhere by fiddling with percent
* instead of forgetting fewer levels. * instead of forgetting fewer levels.
*/ */
indices[0] = 0; /* lint suppression */
for (count = 0, i = 0; i <= maxl; i++) for (count = 0, i = 0; i <= maxl; i++)
if ((level_info[i].flags & VISITED) if ((level_info[i].flags & VISITED)
&& !(level_info[i].flags & FORGOTTEN) && i != this_lev) { && !(level_info[i].flags & FORGOTTEN) && i != this_lev) {
@@ -827,13 +831,15 @@ int percent;
if (percent > 100) if (percent > 100)
percent = 100; percent = 100;
randomize(indices, count); if (count > 0) {
randomize(indices, count);
/* forget first % of randomized indices */ /* forget first % of randomized indices */
count = ((count * percent) + 50) / 100; count = ((count * percent) + 50) / 100;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
level_info[indices[i]].flags |= FORGOTTEN; level_info[indices[i]].flags |= FORGOTTEN;
forget_mapseen(indices[i]); forget_mapseen(indices[i]);
}
} }
} }

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 zap.c $NHDT-Date: 1447475947 2015/11/14 04:39:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.235 $ */ /* NetHack 3.6 zap.c $NHDT-Date: 1447987787 2015/11/20 02:49:47 $ $NHDT-Branch: master $:$NHDT-Revision: 1.236 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -3322,8 +3322,7 @@ int dx, dy;
dy = ydir[i]; dy = ydir[i];
bhitpos.x += dx; bhitpos.x += dx;
bhitpos.y += dy; bhitpos.y += dy;
if (MON_AT(bhitpos.x, bhitpos.y)) { if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
mtmp = m_at(bhitpos.x, bhitpos.y);
m_respond(mtmp); m_respond(mtmp);
tmp_at(DISP_END, 0); tmp_at(DISP_END, 0);
return mtmp; return mtmp;