part2: remediate some nonnull-related compiler warnings

do.c:296:16: warning: nonnull parameter 'obj' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
  296 |         while (obj && (otmp = obj_nexto_xy(obj, x, y, TRUE)) != 0) {
      |                ^~~ ~~
../include/extern.h:538:43: note: declared 'nonnull' here
  538 |                             const char *) NONNULLPTRS;
      |                                           ^
../include/tradstdc.h:378:36: note: expanded from macro 'NONNULLPTRS'
  378 | #define NONNULLPTRS __attribute__((nonnull))
      |                                    ^
1 warning generated.

invent.c:807:12: warning: nonnull parameter 'objlist' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
  807 |     while (objlist) {
      |     ~~~~~  ^~~~~~~
../include/extern.h:1230:61: note: declared 'nonnull' here
 1230 | extern struct obj *merge_choice(struct obj *, struct obj *) NONNULLPTRS;
      |                                                             ^
../include/tradstdc.h:378:36: note: expanded from macro 'NONNULLPTRS'
  378 | #define NONNULLPTRS __attribute__((nonnull))
      |                                    ^
1 warning generated.

monmove.c:2091:23: warning: nonnull parameter 'mtmp' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
 2091 |     boolean is_pet = (mtmp && mtmp->mtame && !mtmp->isminion);
      |                       ^~~~ ~~
../include/extern.h:1844:67: note: declared 'nonnull' here
 1844 | extern boolean undesirable_disp(struct monst *, coordxy, coordxy) NONNULLARG1;
      |                                                                   ^
../include/tradstdc.h:379:36: note: expanded from macro 'NONNULLARG1'
  379 | #define NONNULLARG1 __attribute__((nonnull (1)))
      |                                    ^
1 warning generated.

nhlua.c:2095:9: warning: nonnull parameter 'L' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
 2095 |     if (L)
      |     ~~  ^
../include/extern.h:1985:35: note: declared 'nonnull' here
 1985 | extern void nhl_done(lua_State *) NONNULLARG1;
      |                                   ^
../include/tradstdc.h:379:36: note: expanded from macro 'NONNULLARG1'
  379 | #define NONNULLARG1 __attribute__((nonnull (1)))
      |                                    ^
1 warning generated.

steal.c:59:12: warning: nonnull parameter 'chain' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
   59 |     while (chain && chain->otyp != GOLD_PIECE)
      |            ^~~~~ ~~
../include/extern.h:2910:43: note: declared 'nonnull' here
 2910 | extern struct obj *findgold(struct obj *) NONNULLARG1;
      |                                           ^
../include/tradstdc.h:379:36: note: expanded from macro 'NONNULLARG1'
  379 | #define NONNULLARG1 __attribute__((nonnull (1)))
      |                                    ^
1 warning generated.

utf8map.c:232:9: warning: nonnull parameter 'gmap' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
  232 |     if (gmap) {
      |     ~~  ^~~~
../include/extern.h:3318:28: note: declared 'nonnull' here
 3318 |               long ucolor) NONNULLPTRS;
      |                            ^
../include/tradstdc.h:378:36: note: expanded from macro 'NONNULLPTRS'
  378 | #define NONNULLPTRS __attribute__((nonnull))
      |                                    ^
1 warning generated.

worn.c:895:15: warning: nonnull parameter 'objchain' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
  895 |     if (on && objchain)
      |            ~~ ^~~~~~~~
../include/extern.h:3664:51: note: declared 'nonnull' here
 3664 | extern void bypass_objlist(struct obj *, boolean) NONNULLARG1;
      |                                                   ^
../include/tradstdc.h:379:36: note: expanded from macro 'NONNULLARG1'
  379 | #define NONNULLARG1 __attribute__((nonnull (1)))
      |                                    ^
worn.c:897:12: warning: nonnull parameter 'objchain' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
  897 |     while (objchain) {
      |     ~~~~~  ^~~~~~~~
../include/extern.h:3664:51: note: declared 'nonnull' here
 3664 | extern void bypass_objlist(struct obj *, boolean) NONNULLARG1;
      |                                                   ^
../include/tradstdc.h:379:36: note: expanded from macro 'NONNULLARG1'
  379 | #define NONNULLARG1 __attribute__((nonnull (1)))
      |                                    ^
worn.c:908:12: warning: nonnull parameter 'objchain' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
  908 |     while (objchain) {
      |     ~~~~~  ^~~~~~~~
../include/extern.h:3665:53: note: declared 'nonnull' here
 3665 | extern struct obj *nxt_unbypassed_obj(struct obj *) NONNULLARG1;
      |                                                     ^
../include/tradstdc.h:379:36: note: expanded from macro 'NONNULLARG1'
  379 | #define NONNULLARG1 __attribute__((nonnull (1)))
      |                                    ^
3 warnings generated.
This commit is contained in:
nhmall
2023-12-14 20:06:57 -05:00
parent 978ec6a3a7
commit 6467b983eb
7 changed files with 53 additions and 39 deletions

View File

@@ -292,14 +292,17 @@ flooreffects(struct obj *obj, coordxy x, coordxy y, const char *verb)
res = TRUE;
}
} else if (obj->globby) {
struct obj *globbyobj = obj; /* allow obj to be nonnull arg */
/* Globby things like puddings might stick together */
while (obj && (otmp = obj_nexto_xy(obj, x, y, TRUE)) != 0) {
pudding_merge_message(obj, otmp);
while (globbyobj
&& (otmp = obj_nexto_xy(globbyobj, x, y, TRUE)) != 0) {
pudding_merge_message(globbyobj, otmp);
/* intentionally not getting the melded object; obj_meld may set
* obj to null. */
(void) obj_meld(&obj, &otmp);
(void) obj_meld(&globbyobj, &otmp);
}
res = (boolean) !obj;
res = (boolean) !globbyobj;
} else if (gc.context.mon_moving && IS_ALTAR(levl[x][y].typ)
&& cansee(x,y)) {
doaltarobj(obj);

View File

@@ -783,6 +783,7 @@ merge_choice(struct obj *objlist, struct obj *obj)
{
struct monst *shkp;
int save_nocharge;
struct obj *objlist2;
if (obj->otyp == SCR_SCARE_MONSTER) /* punt on these */
return (struct obj *) 0;
@@ -804,13 +805,14 @@ merge_choice(struct obj *objlist, struct obj *obj)
else if (inhishop(shkp))
return (struct obj *) 0;
}
while (objlist) {
if (mergable(objlist, obj))
objlist2 = objlist; /* allow objlist arg to be nonnull w/o a warning */
while (objlist2) {
if (mergable(objlist2, obj))
break;
objlist = objlist->nobj;
objlist2 = objlist2->nobj;
}
obj->no_charge = save_nocharge;
return objlist;
return objlist2;
}
/* merge obj with otmp and delete obj if types agree */

View File

@@ -2088,7 +2088,7 @@ undesirable_disp(
coordxy x,
coordxy y) /* spot 'mtmp' is considering moving to */
{
boolean is_pet = (mtmp && mtmp->mtame && !mtmp->isminion);
boolean is_pet = (mtmp->mtame && !mtmp->isminion);
struct trap *trap = t_at(x, y);
if (is_pet) {

View File

@@ -2092,8 +2092,10 @@ RESTORE_WARNING_CONDEXPR_IS_CONSTANT
void
nhl_done(lua_State *L)
{
if (L)
lua_close(L);
lua_State *L2 = L; /* allow arg to be declared nonnull */
if (L2)
lua_close(L2);
iflags.in_lua = FALSE;
}

View File

@@ -54,8 +54,10 @@ somegold(long lmoney)
* Deals in gold only, as leprechauns don't care for lesser coins.
*/
struct obj *
findgold(register struct obj* chain)
findgold(register struct obj* argchain)
{
struct obj *chain = argchain; /* allow arg to be nonnull */
while (chain && chain->otyp != GOLD_PIECE)
chain = chain->nobj;
return chain;

View File

@@ -228,26 +228,27 @@ set_map_u(glyph_map *gmap, uint32 utf32ch, const uint8 *utf8str, long ucolor)
{
static uint32_t closecolor = 0;
static int clridx = 0;
glyph_map *tmpgm = gmap;
if (gmap) {
if (gmap->u == 0) {
gmap->u = (struct unicode_representation *) alloc(sizeof *gmap->u);
gmap->u->utf8str = 0;
}
if (gmap->u->utf8str != 0) {
free(gmap->u->utf8str);
gmap->u->utf8str = 0;
}
gmap->u->utf8str = (uint8 *) dupstr((const char *) utf8str);
gmap->u->ucolor = ucolor;
if (closest_color(ucolor, &closecolor, &clridx))
gmap->u->u256coloridx = clridx;
else
gmap->u->u256coloridx = 0;
gmap->u->utf32ch = utf32ch;
return 1;
if (!tmpgm)
return 0;
if (gmap->u == 0) {
gmap->u = (struct unicode_representation *) alloc(sizeof *gmap->u);
gmap->u->utf8str = 0;
}
return 0;
if (gmap->u->utf8str != 0) {
free(gmap->u->utf8str);
gmap->u->utf8str = 0;
}
gmap->u->utf8str = (uint8 *) dupstr((const char *) utf8str);
gmap->u->ucolor = ucolor;
if (closest_color(ucolor, &closecolor, &clridx))
gmap->u->u256coloridx = clridx;
else
gmap->u->u256coloridx = 0;
gmap->u->utf32ch = utf32ch;
return 1;
}

View File

@@ -892,11 +892,13 @@ bypass_objlist(
struct obj *objchain,
boolean on) /* TRUE => set, FALSE => clear */
{
if (on && objchain)
struct obj *objchain2 = objchain; /* allow objchain arg1 to be nonnull */
if (on && objchain2)
gc.context.bypasses = TRUE;
while (objchain) {
objchain->bypass = on ? 1 : 0;
objchain = objchain->nobj;
while (objchain2) {
objchain2->bypass = on ? 1 : 0;
objchain2 = objchain2->nobj;
}
}
@@ -905,14 +907,16 @@ bypass_objlist(
struct obj *
nxt_unbypassed_obj(struct obj *objchain)
{
while (objchain) {
if (!objchain->bypass) {
bypass_obj(objchain);
struct obj *objchain2 = objchain; /* allow objchain arg1 to be nonnull */
while (objchain2) {
if (!objchain2->bypass) {
bypass_obj(objchain2);
break;
}
objchain = objchain->nobj;
objchain2 = objchain2->nobj;
}
return objchain;
return objchain2;
}
/* like nxt_unbypassed_obj() but operates on sortloot_item array rather