From 171fb90746b9634dc3411b23afc5fcdf607f7121 Mon Sep 17 00:00:00 2001 From: PatR <rankin@nethack.org> Date: Fri, 4 Dec 2015 14:58:49 -0800 Subject: [PATCH] !DEBUG warnings With DEBUG suppressed, I started getting 16 warning: empty body in an if-statement and 2 warning: empty body in an else-statement from gcc. Using braces for an empty block instead of just ';' avoids the warning: if (foo) debugpline("foo"); is bad, if (bar) { debugpline("bar"); } is good. ;-) The changes to lint.h are just precautionary. modified: include/lint.h src/attrib.c, bones.c, dbridge.c, dig.c, eat.c, makemon.c, mkmaze.c, mon.c, sp_lev.c --- include/lint.h | 22 ++++++++++++---------- src/attrib.c | 10 ++++++---- src/bones.c | 5 +++-- src/dbridge.c | 19 +++++++++++-------- src/dig.c | 5 +++-- src/eat.c | 39 ++++++++++++++++++++------------------- src/makemon.c | 8 +++++--- src/mkmaze.c | 9 +++++---- src/mon.c | 4 ++-- src/sp_lev.c | 5 +++-- 10 files changed, 70 insertions(+), 56 deletions(-) diff --git a/include/lint.h b/include/lint.h index 8fb79b4a9..c50446405 100644 --- a/include/lint.h +++ b/include/lint.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 lint.h $NHDT-Date: 1430897871 2015/05/06 07:37:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */ +/* NetHack 3.6 lint.h $NHDT-Date: 1449269910 2015/12/04 22:58:30 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.3 $ */ /* NetHack may be freely redistributed. See license for details. */ /* @@ -36,19 +36,21 @@ extern unsigned nhUse_dummy; #ifdef DEBUG #define showdebug(file) debugcore(file, TRUE) #define explicitdebug(file) debugcore(file, FALSE) -#define ifdebug(stmt) \ - do { \ - if (showdebug(__FILE__)) \ - stmt; \ +#define ifdebug(stmt) \ + do { \ + if (showdebug(__FILE__)) { \ + stmt; \ + } \ } while (0) #ifdef _MSC_VER /* if we have microsoft's C runtime we can use these instead */ #include <crtdbg.h> -#define crtdebug(stmt) \ - do { \ - if (showdebug(__FILE__)) \ - stmt; \ - _RPT0(_CRT_WARN, "\n"); \ +#define crtdebug(stmt) \ + do { \ + if (showdebug(__FILE__)) { \ + stmt; \ + } \ + _RPT0(_CRT_WARN, "\n"); \ } while (0) #define debugpline0(str) crtdebug(_RPT0(_CRT_WARN, str)) #define debugpline1(fmt, arg) crtdebug(_RPT1(_CRT_WARN, fmt, arg)) diff --git a/src/attrib.c b/src/attrib.c index b0ee0fc11..3866dbf26 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 attrib.c $NHDT-Date: 1446975460 2015/11/08 09:37:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.49 $ */ +/* NetHack 3.6 attrib.c $NHDT-Date: 1449269911 2015/12/04 22:58:31 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.51 $ */ /* Copyright 1988, 1989, 1990, 1992, M. Stephenson */ /* NetHack may be freely redistributed. See license for details. */ @@ -470,8 +470,9 @@ exerchk() /* Check out the periodic accumulations */ exerper(); - if (moves >= context.next_attrib_check) + if (moves >= context.next_attrib_check) { debugpline1("exerchk: ready to test. multi = %d.", multi); + } /* Are we ready for a test? */ if (moves >= context.next_attrib_check && !multi) { debugpline0("exerchk: testing."); @@ -515,8 +516,9 @@ exerchk() ? "Dex" : (i == A_CON) ? "Con" - : (i == A_CHA) ? "Cha?" - : "???", + : (i == A_CHA) + ? "Cha?" + : "???", ax); /* * Law of diminishing returns (Part III): diff --git a/src/bones.c b/src/bones.c index b068e751a..7ca192599 100644 --- a/src/bones.c +++ b/src/bones.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 bones.c $NHDT-Date: 1446369463 2015/11/01 09:17:43 $ $NHDT-Branch: master $:$NHDT-Revision: 1.65 $ */ +/* NetHack 3.6 bones.c $NHDT-Date: 1449269914 2015/12/04 22:58:34 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.66 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985,1993. */ /* NetHack may be freely redistributed. See license for details. */ @@ -608,9 +608,10 @@ getbones() if (has_mname(mtmp)) sanitize_name(MNAME(mtmp)); if (mtmp->mhpmax == DEFUNCT_MONSTER) { - if (wizard) + if (wizard) { debugpline1("Removing defunct monster %s from bones.", mtmp->data->mname); + } mongone(mtmp); } else /* to correctly reset named artifacts on the level */ diff --git a/src/dbridge.c b/src/dbridge.c index 1dc43ad4b..7d6bda397 100644 --- a/src/dbridge.c +++ b/src/dbridge.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dbridge.c $NHDT-Date: 1446955279 2015/11/08 04:01:19 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */ +/* NetHack 3.6 dbridge.c $NHDT-Date: 1449269914 2015/12/04 22:58:34 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.35 $ */ /* Copyright (c) 1989 by Jean-Christophe Collet */ /* NetHack may be freely redistributed. See license for details. */ @@ -509,8 +509,9 @@ boolean chunks; { int misses; - if (chunks) + if (chunks) { debugpline0("Do chunks miss?"); + } if (automiss(etmp)) return TRUE; @@ -590,13 +591,14 @@ struct entity *etmp; return; } if (e_missed(etmp, FALSE)) { - if (at_portcullis) + if (at_portcullis) { pline_The("portcullis misses %s!", e_nam(etmp)); - else + } else { debugpline1("The drawbridge misses %s!", e_nam(etmp)); - if (e_survives_at(etmp, oldx, oldy)) + } + if (e_survives_at(etmp, oldx, oldy)) { return; - else { + } else { debugpline0("Mon can't survive here"); if (at_portcullis) must_jump = TRUE; @@ -978,10 +980,11 @@ int x, y; pline("%s hit by a huge chunk of metal!", E_phrase(etmp1, "are")); } else { - if (!Deaf && !is_u(etmp1) && !is_pool(x, y)) + if (!Deaf && !is_u(etmp1) && !is_pool(x, y)) { You_hear("a crushing sound."); - else + } else { debugpline1("%s from shrapnel", E_phrase(etmp1, "die")); + } } killer.format = KILLED_BY_AN; Strcpy(killer.name, "collapsing drawbridge"); diff --git a/src/dig.c b/src/dig.c index 0d1c24187..bbfef5d0b 100644 --- a/src/dig.c +++ b/src/dig.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 dig.c $NHDT-Date: 1446369465 2015/11/01 09:17:45 $ $NHDT-Branch: master $:$NHDT-Revision: 1.99 $ */ +/* NetHack 3.6 dig.c $NHDT-Date: 1449269915 2015/12/04 22:58:35 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.103 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1864,8 +1864,9 @@ int x, y; { struct obj *otmp, *otmp2; - if (level.objects[x][y] != (struct obj *) 0) + if (level.objects[x][y] != (struct obj *) 0) { debugpline2("bury_objs: at <%d,%d>", x, y); + } for (otmp = level.objects[x][y]; otmp; otmp = otmp2) otmp2 = bury_an_obj(otmp, (boolean *) 0); diff --git a/src/eat.c b/src/eat.c index 8056cc190..fe3e4e071 100644 --- a/src/eat.c +++ b/src/eat.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 eat.c $NHDT-Date: 1446854226 2015/11/06 23:57:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.152 $ */ +/* NetHack 3.6 eat.c $NHDT-Date: 1449269916 2015/12/04 22:58:36 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.154 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -728,56 +728,57 @@ register struct permonst *ptr; { int res = 0; +#ifdef DEBUG +#define ifdebugresist(Msg) \ + do { \ + if (res) \ + debugpline0(Msg); \ + } while (0) +#else +#define ifdebugresist(Msg) /*empty*/ +#endif switch (type) { case FIRE_RES: res = (ptr->mconveys & MR_FIRE) != 0; - if (res) - debugpline0("can get fire resistance"); + ifdebugresist("can get fire resistance"); break; case SLEEP_RES: res = (ptr->mconveys & MR_SLEEP) != 0; - if (res) - debugpline0("can get sleep resistance"); + ifdebugresist("can get sleep resistance"); break; case COLD_RES: res = (ptr->mconveys & MR_COLD) != 0; - if (res) - debugpline0("can get cold resistance"); + ifdebugresist("can get cold resistance"); break; case DISINT_RES: res = (ptr->mconveys & MR_DISINT) != 0; - if (res) - debugpline0("can get disintegration resistance"); + ifdebugresist("can get disintegration resistance"); break; case SHOCK_RES: /* shock (electricity) resistance */ res = (ptr->mconveys & MR_ELEC) != 0; - if (res) - debugpline0("can get shock resistance"); + ifdebugresist("can get shock resistance"); break; case POISON_RES: res = (ptr->mconveys & MR_POISON) != 0; - if (res) - debugpline0("can get poison resistance"); + ifdebugresist("can get poison resistance"); break; case TELEPORT: res = can_teleport(ptr); - if (res) - debugpline0("can get teleport"); + ifdebugresist("can get teleport"); break; case TELEPORT_CONTROL: res = control_teleport(ptr); - if (res) - debugpline0("can get teleport control"); + ifdebugresist("can get teleport control"); break; case TELEPAT: res = telepathic(ptr); - if (res) - debugpline0("can get telepathy"); + ifdebugresist("can get telepathy"); break; default: /* res stays 0 */ break; } +#undef ifdebugresist return res; } diff --git a/src/makemon.c b/src/makemon.c index c2db6f5d1..102379e4a 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 makemon.c $NHDT-Date: 1449052582 2015/12/02 10:36:22 $ $NHDT-Branch: master $:$NHDT-Revision: 1.104 $ */ +/* NetHack 3.6 makemon.c $NHDT-Date: 1449269917 2015/12/04 22:58:37 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.105 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -857,9 +857,10 @@ boolean ghostly; mvitals[mndx].born++; if ((int) mvitals[mndx].born >= lim && !(mons[mndx].geno & G_NOGEN) && !(mvitals[mndx].mvflags & G_EXTINCT)) { - if (wizard) + if (wizard) { debugpline1("Automatically extinguished %s.", makeplural(mons[mndx].mname)); + } mvitals[mndx].mvflags |= G_EXTINCT; reset_rndmonst(mndx); } @@ -1072,9 +1073,10 @@ int mmflags; already been genocided, return */ if (mvitals[mndx].mvflags & G_GENOD) return (struct monst *) 0; - if (wizard && (mvitals[mndx].mvflags & G_EXTINCT)) + if (wizard && (mvitals[mndx].mvflags & G_EXTINCT)) { debugpline1("Explicitly creating extinct monster %s.", mons[mndx].mname); + } } else { /* make a random (common) monster that can survive here. * (the special levels ask for random monsters at specific diff --git a/src/mkmaze.c b/src/mkmaze.c index d1f372b64..eddf6fbd1 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mkmaze.c $NHDT-Date: 1448013594 2015/11/20 09:59:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.41 $ */ +/* NetHack 3.6 mkmaze.c $NHDT-Date: 1449269918 2015/12/04 22:58:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.42 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -616,9 +616,10 @@ register const char *s; y_range = y_maze_max - y_maze_min - 2 * INVPOS_Y_MARGIN - 1; if (x_range <= INVPOS_X_MARGIN || y_range <= INVPOS_Y_MARGIN - || (x_range * y_range) <= (INVPOS_DISTANCE * INVPOS_DISTANCE)) - debugpline2("inv_pos: maze is too small! (%d x %d)", x_maze_max, - y_maze_max); + || (x_range * y_range) <= (INVPOS_DISTANCE * INVPOS_DISTANCE)) { + debugpline2("inv_pos: maze is too small! (%d x %d)", + x_maze_max, y_maze_max); + } inv_pos.x = inv_pos.y = 0; /*{occupied() => invocation_pos()}*/ do { x = rn1(x_range, x_maze_min + INVPOS_X_MARGIN + 1); diff --git a/src/mon.c b/src/mon.c index 8116d7877..ade596810 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mon.c $NHDT-Date: 1447475944 2015/11/14 04:39:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.196 $ */ +/* NetHack 3.6 mon.c $NHDT-Date: 1449269918 2015/12/04 22:58:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.199 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1470,7 +1470,7 @@ struct monst *mtmp, *mtmp2; /* transfer the monster's inventory */ for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) { if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp) - debugpline0("replmon: minvent inconsistency"); + impossible("replmon: minvent inconsistency"); otmp->ocarry = mtmp2; } mtmp->minvent = 0; diff --git a/src/sp_lev.c b/src/sp_lev.c index eb0c65793..dc454128a 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 sp_lev.c $NHDT-Date: 1449051497 2015/12/02 10:18:17 $ $NHDT-Branch: master $:$NHDT-Revision: 1.76 $ */ +/* NetHack 3.6 sp_lev.c $NHDT-Date: 1449269920 2015/12/04 22:58:40 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.77 $ */ /* Copyright (c) 1989 by Jean-Christophe Collet */ /* NetHack may be freely redistributed. See license for details. */ @@ -1033,8 +1033,9 @@ chk: lev = &levl[x][y]; for (; y <= ymax; y++) { if (lev++->typ) { - if (!vault) + if (!vault) { debugpline2("strange area [%d,%d] in check_room.", x, y); + } if (!rn2(3)) return FALSE; if (x < *lowx) -- 2.40.0