Fix some warnings from clang's static code analyzer

This commit is contained in:
Pasi Kallinen
2015-11-18 22:54:28 +02:00
parent 5e5a78fdb2
commit dc09a991fe
14 changed files with 31 additions and 15 deletions
+1 -1
View File
@@ -73,7 +73,7 @@
* canseemon() or canspotmon() which already check that. * canseemon() or canspotmon() which already check that.
*/ */
#define see_with_infrared(mon) \ #define see_with_infrared(mon) \
(!Blind && Infravision && infravisible(mon->data) \ (!Blind && Infravision && mon && infravisible(mon->data) \
&& couldsee(mon->mx, mon->my)) && couldsee(mon->mx, mon->my))
/* /*
+2 -2
View File
@@ -2036,8 +2036,8 @@ boolean quietly;
You("don't have enough room in here."); You("don't have enough room in here.");
return FALSE; return FALSE;
} }
x = cc->x; x = cc ? cc->x : u.ux;
y = cc->y; y = cc ? cc->y : u.uy;
if (!isok(x, y)) { if (!isok(x, y)) {
if (!quietly) if (!quietly)
You("cannot put the figurine there."); You("cannot put the figurine there.");
+4 -1
View File
@@ -1404,7 +1404,10 @@ arti_invoke(obj)
struct obj *obj; struct obj *obj;
{ {
register const struct artifact *oart = get_artifact(obj); register const struct artifact *oart = get_artifact(obj);
if (!obj) {
impossible("arti_invoke without obj");
return 0;
}
if (!oart || !oart->inv_prop) { if (!oart || !oart->inv_prop) {
if (obj->otyp == CRYSTAL_BALL) if (obj->otyp == CRYSTAL_BALL)
use_crystal_ball(&obj); use_crystal_ball(&obj);
+2 -3
View File
@@ -385,7 +385,6 @@ extcmd_via_menu()
biggest = 0; biggest = 0;
while (!ret) { while (!ret) {
i = n = 0; i = n = 0;
accelerator = 0;
any = zeroany; any = zeroany;
/* populate choices */ /* populate choices */
for (efp = extcmdlist; efp->ef_txt; efp++) { for (efp = extcmdlist; efp->ef_txt; efp++) {
@@ -421,7 +420,7 @@ extcmd_via_menu()
/* otherwise... */ /* otherwise... */
win = create_nhwindow(NHW_MENU); win = create_nhwindow(NHW_MENU);
start_menu(win); start_menu(win);
prevaccelerator = 0; accelerator = prevaccelerator = 0;
acount = 0; acount = 0;
for (i = 0; choices[i]; ++i) { for (i = 0; choices[i]; ++i) {
accelerator = choices[i]->ef_txt[matchlevel]; accelerator = choices[i]->ef_txt[matchlevel];
@@ -1769,7 +1768,7 @@ int final;
/* when mounted, Wounded_legs applies to steed rather than to /* when mounted, Wounded_legs applies to steed rather than to
hero; we only report steed's wounded legs in wizard mode */ hero; we only report steed's wounded legs in wizard mode */
if (u.usteed) { /* not `Riding' here */ if (u.usteed) { /* not `Riding' here */
if (wizard) { if (wizard && steedname) {
Strcpy(buf, steedname); Strcpy(buf, steedname);
*buf = highc(*buf); *buf = highc(*buf);
enl_msg(buf, " has", " had", " wounded legs", ""); enl_msg(buf, " has", " had", " wounded legs", "");
+1 -1
View File
@@ -388,7 +388,7 @@ const char *verb;
static char wholebuf[80]; static char wholebuf[80];
Strcpy(wholebuf, is_u(etmp) ? "You" : Monnam(etmp->emon)); Strcpy(wholebuf, is_u(etmp) ? "You" : Monnam(etmp->emon));
if (!*verb) if (!verb || !*verb)
return wholebuf; return wholebuf;
Strcat(wholebuf, " "); Strcat(wholebuf, " ");
if (is_u(etmp)) if (is_u(etmp))
+4
View File
@@ -1123,6 +1123,10 @@ register struct obj *otmp;
{ {
boolean was_blind = Blind, changed = FALSE; boolean was_blind = Blind, changed = FALSE;
if (!otmp) {
impossible("Blindf_off without otmp");
return;
}
context.takeoff.mask &= ~W_TOOL; context.takeoff.mask &= ~W_TOOL;
setworn((struct obj *) 0, otmp->owornmask); setworn((struct obj *) 0, otmp->owornmask);
off_msg(otmp); off_msg(otmp);
+4 -1
View File
@@ -271,7 +271,10 @@ STATIC_OVL void
recalc_wt() recalc_wt()
{ {
struct obj *piece = context.victual.piece; struct obj *piece = context.victual.piece;
if (!piece) {
impossible("recalc_wt without piece");
return;
}
debugpline1("Old weight = %d", piece->owt); debugpline1("Old weight = %d", piece->owt);
debugpline2("Used time = %d, Req'd time = %d", context.victual.usedtime, debugpline2("Used time = %d, Req'd time = %d", context.victual.usedtime,
context.victual.reqtime); context.victual.reqtime);
+1 -1
View File
@@ -627,7 +627,7 @@ boolean taken;
{ {
char c = 0, defquery; char c = 0, defquery;
char qbuf[QBUFSZ]; char qbuf[QBUFSZ];
boolean ask; boolean ask = FALSE;
if (invent && !done_stopprint) { if (invent && !done_stopprint) {
if (taken) if (taken)
+3 -1
View File
@@ -64,8 +64,10 @@ lock_action()
return actions[3]; /* same as lock_pick */ return actions[3]; /* same as lock_pick */
else if (xlock.door) else if (xlock.door)
return actions[0]; /* "unlocking the door" */ return actions[0]; /* "unlocking the door" */
else else if (xlock.box)
return xlock.box->otyp == CHEST ? actions[1] : actions[2]; return xlock.box->otyp == CHEST ? actions[1] : actions[2];
else
return actions[3];
} }
/* try to open/close a lock */ /* try to open/close a lock */
+2
View File
@@ -391,6 +391,8 @@ unsigned corpseflags;
} }
/* All special cases should precede the G_NOCORPSE check */ /* All special cases should precede the G_NOCORPSE check */
if (!obj) return NULL;
/* if polymorph or undead turning has killed this monster, /* if polymorph or undead turning has killed this monster,
prevent the same attack beam from hitting its corpse */ prevent the same attack beam from hitting its corpse */
if (context.bypasses) if (context.bypasses)
+2 -2
View File
@@ -797,7 +797,7 @@ gcrownu()
case A_NEUTRAL: case A_NEUTRAL:
if (class_gift != STRANGE_OBJECT) { if (class_gift != STRANGE_OBJECT) {
; /* already got bonus above */ ; /* already got bonus above */
} else if (in_hand) { } else if (obj && in_hand) {
Your("%s goes snicker-snack!", xname(obj)); Your("%s goes snicker-snack!", xname(obj));
obj->dknown = TRUE; obj->dknown = TRUE;
} else if (!already_exists) { } else if (!already_exists) {
@@ -819,7 +819,7 @@ gcrownu()
Sprintf(swordbuf, "%s sword", hcolor(NH_BLACK)); Sprintf(swordbuf, "%s sword", hcolor(NH_BLACK));
if (class_gift != STRANGE_OBJECT) { if (class_gift != STRANGE_OBJECT) {
; /* already got bonus above */ ; /* already got bonus above */
} else if (in_hand) { } else if (obj && in_hand) {
Your("%s hums ominously!", swordbuf); Your("%s hums ominously!", swordbuf);
obj->dknown = TRUE; obj->dknown = TRUE;
} else if (!already_exists) { } else if (!already_exists) {
+3
View File
@@ -976,6 +976,9 @@ packed_coord pos;
schar try_x, try_y; schar try_x, try_y;
register int trycnt = 0; 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); get_location_coord(&try_x, &try_y, DRY, croom, pos);
if (levl[try_x][try_y].typ != ROOM) { if (levl[try_x][try_y].typ != ROOM) {
do { do {
+1 -1
View File
@@ -3764,7 +3764,7 @@ STATIC_OVL void
move_into_trap(ttmp) move_into_trap(ttmp)
struct trap *ttmp; struct trap *ttmp;
{ {
int bc; int bc = 0;
xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy; xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy;
boolean unused; boolean unused;
+1 -1
View File
@@ -959,7 +959,7 @@ int otyp;
break; break;
} }
while (skills->skill != P_NONE) { while (skills && skills->skill != P_NONE) {
if (skills->skill == this_skill) if (skills->skill == this_skill)
return FALSE; return FALSE;
++skills; ++skills;