From: PatR Date: Fri, 20 Nov 2015 02:49:50 +0000 (-0800) Subject: warning suppression X-Git-Tag: NetHack-3.6.0_RC01~44^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2a567737eb06a70cd4d35d7dde96824d0c643c3;p=nethack 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. --- diff --git a/src/muse.c b/src/muse.c index d16a8f212..012ac8b8f 100644 --- a/src/muse.c +++ b/src/muse.c @@ -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 $ */ -/* Copyright (C) 1990 by Ken Arromdee */ +/* 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 */ /* 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(mquaffmsg, (struct monst *, struct obj *)); STATIC_PTR int FDECL(mbhitm, (struct monst *, struct obj *)); -STATIC_DCL void FDECL(mbhit, - (struct monst *, int, int FDECL((*), (MONST_P, OBJ_P)), - int FDECL((*), (OBJ_P, OBJ_P)), struct obj *)); +STATIC_DCL void FDECL(mbhit, (struct monst *, int, + int FDECL((*), (MONST_P, OBJ_P)), + int FDECL((*), (OBJ_P, OBJ_P)), struct obj *)); STATIC_DCL void FDECL(you_aggravate, (struct monst *)); -STATIC_DCL void FDECL(mon_consume_unstone, - (struct monst *, struct obj *, BOOLEAN_P, BOOLEAN_P)); -STATIC_DCL boolean -FDECL(cures_stoning, (struct monst *, struct obj *, BOOLEAN_P)); +STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *, struct obj *, + BOOLEAN_P, BOOLEAN_P)); +STATIC_DCL boolean FDECL(cures_stoning, (struct monst *, struct obj *, + BOOLEAN_P)); STATIC_DCL boolean FDECL(mcould_eat_tin, (struct monst *)); -STATIC_DCL boolean -FDECL(muse_unslime, (struct monst *, struct obj *, BOOLEAN_P)); +STATIC_DCL boolean FDECL(muse_unslime, (struct monst *, struct obj *, + BOOLEAN_P)); STATIC_DCL int FDECL(cures_sliming, (struct monst *, struct obj *)); STATIC_DCL boolean FDECL(green_mon, (struct monst *)); @@ -48,17 +48,16 @@ static struct musable { */ } m; static int trapx, trapy; -static boolean zap_oseen; -/* for wands which use mbhitm and are zapped at players. We usually - * want an oseen local to the function, but this is impossible since the - * function mbhitm has to be compatible with the normal zap routines, - * and those routines don't remember who zapped the wand. - */ +static boolean zap_oseen; /* for wands which use mbhitm and are zapped at + * players. We usually want an oseen local to + * the function, but this is impossible since the + * function mbhitm has to be compatible with the + * 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 * the item. Returns 0 if nothing happened, 2 if the monster can't do - * anything - * (i.e. it teleported) and 1 if it's dead. + * anything (i.e. it teleported) and 1 if it's dead. */ STATIC_OVL int precheck(mon, obj) @@ -93,12 +92,11 @@ struct obj *obj; if (vis) { pline( "As %s opens the bottle, an enormous %s emerges!", - mon_nam(mon), - Hallucination ? rndmonnam(NULL) - : (const char *) "ghost"); - pline( - "%s is frightened to death, and unable to move.", - Monnam(mon)); + mon_nam(mon), + Hallucination ? rndmonnam(NULL) + : (const char *) "ghost"); + pline("%s is frightened to death, and unable to move.", + Monnam(mon)); } 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) { (*fhitm)(&youmonst, obj); range -= 3; - } else if (MON_AT(bhitpos.x, bhitpos.y)) { - mtmp = m_at(bhitpos.x, bhitpos.y); + } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { if (cansee(bhitpos.x, bhitpos.y) && !canspotmon(mtmp)) map_invisible(bhitpos.x, bhitpos.y); (*fhitm)(mtmp, obj); diff --git a/src/read.c b/src/read.c index d4fd16923..162bad878 100644 --- a/src/read.c +++ b/src/read.c @@ -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. */ /* NetHack may be freely redistributed. See license for details. */ @@ -739,17 +739,20 @@ int percent; return; } + indices[0] = 0; /* lint suppression */ for (count = 0, i = 1; i < NUM_OBJECTS; i++) if (OBJ_DESCR(objects[i]) && (objects[i].oc_name_known || objects[i].oc_uname)) indices[count++] = i; - randomize(indices, count); + if (count > 0) { + randomize(indices, count); - /* forget first % of randomized indices */ - count = ((count * percent) + rn2(100)) / 100; - for (i = 0; i < count; i++) - forget_single_object(indices[i]); + /* forget first % of randomized indices */ + count = ((count * percent) + rn2(100)) / 100; + for (i = 0; i < count; i++) + forget_single_object(indices[i]); + } } /* Forget some or all of map (depends on parameters). */ @@ -815,6 +818,7 @@ int percent; * shift the forgetting elsewhere by fiddling with percent * instead of forgetting fewer levels. */ + indices[0] = 0; /* lint suppression */ for (count = 0, i = 0; i <= maxl; i++) if ((level_info[i].flags & VISITED) && !(level_info[i].flags & FORGOTTEN) && i != this_lev) { @@ -827,13 +831,15 @@ int percent; if (percent > 100) percent = 100; - randomize(indices, count); + if (count > 0) { + randomize(indices, count); - /* forget first % of randomized indices */ - count = ((count * percent) + 50) / 100; - for (i = 0; i < count; i++) { - level_info[indices[i]].flags |= FORGOTTEN; - forget_mapseen(indices[i]); + /* forget first % of randomized indices */ + count = ((count * percent) + 50) / 100; + for (i = 0; i < count; i++) { + level_info[indices[i]].flags |= FORGOTTEN; + forget_mapseen(indices[i]); + } } } diff --git a/src/zap.c b/src/zap.c index 34c4b6d31..eb3d20e41 100644 --- a/src/zap.c +++ b/src/zap.c @@ -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. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3322,8 +3322,7 @@ int dx, dy; dy = ydir[i]; bhitpos.x += dx; bhitpos.y += dy; - if (MON_AT(bhitpos.x, bhitpos.y)) { - mtmp = m_at(bhitpos.x, bhitpos.y); + if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) { m_respond(mtmp); tmp_at(DISP_END, 0); return mtmp;