From: Pasi Kallinen Date: Wed, 18 Nov 2015 20:54:28 +0000 (+0200) Subject: Fix some warnings from clang's static code analyzer X-Git-Tag: NetHack-3.6.0_RC01~54^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc09a991fec03c252889a9d8e3577c2942133ecf;p=nethack Fix some warnings from clang's static code analyzer --- diff --git a/include/display.h b/include/display.h index fe3c5e62b..4bd8cf924 100644 --- a/include/display.h +++ b/include/display.h @@ -73,7 +73,7 @@ * canseemon() or canspotmon() which already check that. */ #define see_with_infrared(mon) \ - (!Blind && Infravision && infravisible(mon->data) \ + (!Blind && Infravision && mon && infravisible(mon->data) \ && couldsee(mon->mx, mon->my)) /* diff --git a/src/apply.c b/src/apply.c index 952e5fa7b..4f0bf0391 100644 --- a/src/apply.c +++ b/src/apply.c @@ -2036,8 +2036,8 @@ boolean quietly; You("don't have enough room in here."); return FALSE; } - x = cc->x; - y = cc->y; + x = cc ? cc->x : u.ux; + y = cc ? cc->y : u.uy; if (!isok(x, y)) { if (!quietly) You("cannot put the figurine there."); diff --git a/src/artifact.c b/src/artifact.c index 789057932..23c7c49c2 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -1404,7 +1404,10 @@ arti_invoke(obj) struct obj *obj; { register const struct artifact *oart = get_artifact(obj); - + if (!obj) { + impossible("arti_invoke without obj"); + return 0; + } if (!oart || !oart->inv_prop) { if (obj->otyp == CRYSTAL_BALL) use_crystal_ball(&obj); diff --git a/src/cmd.c b/src/cmd.c index 17500699c..8fd20ef0c 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -385,7 +385,6 @@ extcmd_via_menu() biggest = 0; while (!ret) { i = n = 0; - accelerator = 0; any = zeroany; /* populate choices */ for (efp = extcmdlist; efp->ef_txt; efp++) { @@ -421,7 +420,7 @@ extcmd_via_menu() /* otherwise... */ win = create_nhwindow(NHW_MENU); start_menu(win); - prevaccelerator = 0; + accelerator = prevaccelerator = 0; acount = 0; for (i = 0; choices[i]; ++i) { accelerator = choices[i]->ef_txt[matchlevel]; @@ -1769,7 +1768,7 @@ int final; /* when mounted, Wounded_legs applies to steed rather than to hero; we only report steed's wounded legs in wizard mode */ if (u.usteed) { /* not `Riding' here */ - if (wizard) { + if (wizard && steedname) { Strcpy(buf, steedname); *buf = highc(*buf); enl_msg(buf, " has", " had", " wounded legs", ""); diff --git a/src/dbridge.c b/src/dbridge.c index 393831241..1dc43ad4b 100644 --- a/src/dbridge.c +++ b/src/dbridge.c @@ -388,7 +388,7 @@ const char *verb; static char wholebuf[80]; Strcpy(wholebuf, is_u(etmp) ? "You" : Monnam(etmp->emon)); - if (!*verb) + if (!verb || !*verb) return wholebuf; Strcat(wholebuf, " "); if (is_u(etmp)) diff --git a/src/do_wear.c b/src/do_wear.c index 83926a836..ea73cace8 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -1123,6 +1123,10 @@ register struct obj *otmp; { boolean was_blind = Blind, changed = FALSE; + if (!otmp) { + impossible("Blindf_off without otmp"); + return; + } context.takeoff.mask &= ~W_TOOL; setworn((struct obj *) 0, otmp->owornmask); off_msg(otmp); diff --git a/src/eat.c b/src/eat.c index 1cf9c3166..8056cc190 100644 --- a/src/eat.c +++ b/src/eat.c @@ -271,7 +271,10 @@ STATIC_OVL void recalc_wt() { struct obj *piece = context.victual.piece; - + if (!piece) { + impossible("recalc_wt without piece"); + return; + } debugpline1("Old weight = %d", piece->owt); debugpline2("Used time = %d, Req'd time = %d", context.victual.usedtime, context.victual.reqtime); diff --git a/src/end.c b/src/end.c index e7c9da20a..5e1fd0b01 100644 --- a/src/end.c +++ b/src/end.c @@ -627,7 +627,7 @@ boolean taken; { char c = 0, defquery; char qbuf[QBUFSZ]; - boolean ask; + boolean ask = FALSE; if (invent && !done_stopprint) { if (taken) diff --git a/src/lock.c b/src/lock.c index 0f6ab0f71..16f1c63b1 100644 --- a/src/lock.c +++ b/src/lock.c @@ -64,8 +64,10 @@ lock_action() return actions[3]; /* same as lock_pick */ else if (xlock.door) return actions[0]; /* "unlocking the door" */ - else + else if (xlock.box) return xlock.box->otyp == CHEST ? actions[1] : actions[2]; + else + return actions[3]; } /* try to open/close a lock */ diff --git a/src/mon.c b/src/mon.c index 8e251092c..5d476118f 100644 --- a/src/mon.c +++ b/src/mon.c @@ -391,6 +391,8 @@ unsigned corpseflags; } /* All special cases should precede the G_NOCORPSE check */ + if (!obj) return NULL; + /* if polymorph or undead turning has killed this monster, prevent the same attack beam from hitting its corpse */ if (context.bypasses) diff --git a/src/pray.c b/src/pray.c index d6230e708..e3da3e37d 100644 --- a/src/pray.c +++ b/src/pray.c @@ -797,7 +797,7 @@ gcrownu() case A_NEUTRAL: if (class_gift != STRANGE_OBJECT) { ; /* already got bonus above */ - } else if (in_hand) { + } else if (obj && in_hand) { Your("%s goes snicker-snack!", xname(obj)); obj->dknown = TRUE; } else if (!already_exists) { @@ -819,7 +819,7 @@ gcrownu() Sprintf(swordbuf, "%s sword", hcolor(NH_BLACK)); if (class_gift != STRANGE_OBJECT) { ; /* already got bonus above */ - } else if (in_hand) { + } else if (obj && in_hand) { Your("%s hums ominously!", swordbuf); obj->dknown = TRUE; } else if (!already_exists) { diff --git a/src/sp_lev.c b/src/sp_lev.c index 6b555b66b..3388c4c5f 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -976,6 +976,9 @@ packed_coord pos; schar try_x, try_y; register int trycnt = 0; + if (!x || !y) + panic("get_free_room_loc: x or y is null"); + get_location_coord(&try_x, &try_y, DRY, croom, pos); if (levl[try_x][try_y].typ != ROOM) { do { diff --git a/src/trap.c b/src/trap.c index 3bef3ccae..5832eee4c 100644 --- a/src/trap.c +++ b/src/trap.c @@ -3764,7 +3764,7 @@ STATIC_OVL void move_into_trap(ttmp) struct trap *ttmp; { - int bc; + int bc = 0; xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy; boolean unused; diff --git a/src/u_init.c b/src/u_init.c index beca86829..f0c1e3756 100644 --- a/src/u_init.c +++ b/src/u_init.c @@ -959,7 +959,7 @@ int otyp; break; } - while (skills->skill != P_NONE) { + while (skills && skills->skill != P_NONE) { if (skills->skill == this_skill) return FALSE; ++skills;