]> granicus.if.org Git - nethack/commitdiff
Fix some warnings from clang's static code analyzer
authorPasi Kallinen <paxed@alt.org>
Wed, 18 Nov 2015 20:54:28 +0000 (22:54 +0200)
committerPasi Kallinen <paxed@alt.org>
Wed, 18 Nov 2015 20:54:28 +0000 (22:54 +0200)
14 files changed:
include/display.h
src/apply.c
src/artifact.c
src/cmd.c
src/dbridge.c
src/do_wear.c
src/eat.c
src/end.c
src/lock.c
src/mon.c
src/pray.c
src/sp_lev.c
src/trap.c
src/u_init.c

index fe3c5e62bf9037a6100959350248d999d0b98edc..4bd8cf924766c7c9bd6bf90d139c6924cd03f057 100644 (file)
@@ -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))
 
 /*
index 952e5fa7b15c4b5d24bb3adf2834201d55343785..4f0bf03917cd03660ca97f59f08f8b011c899e77 100644 (file)
@@ -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.");
index 78905793255bd30677bd696e33c3bb96aa3f3d9d..23c7c49c2b84d36afc0fbe748245aec47e12188c 100644 (file)
@@ -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);
index 17500699c1a03bd1ba9b9b1ac9579b65a8a2ad1d..8fd20ef0c91af4068bc9edc1d6b957bb89c9e115 100644 (file)
--- 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", "");
index 39383124118f7f9abe813f203d992d386e586bed..1dc43ad4beeefcd19e01bac4371a07612eeb1ef6 100644 (file)
@@ -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))
index 83926a836d4d3f4f7a79c40efd46e051a032d43d..ea73cace85ce6ff87930051c8711902272c89373 100644 (file)
@@ -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);
index 1cf9c31660eafb046a08cf0e6a46cf7c4b77d676..8056cc19092210b6301ad34e138070f2ab165483 100644 (file)
--- 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);
index e7c9da20a95e2a4c13a354f1de1f4c89f30dd8d3..5e1fd0b01c0af8a9229549a6bed3dcb1af9ce861 100644 (file)
--- 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)
index 0f6ab0f71ce203e77c2138bd69480021a1498558..16f1c63b1412e379b4098ea4879380bfb4eb181e 100644 (file)
@@ -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 */
index 8e251092cf4d82fef335bd4d0f110ecc47a390ae..5d476118f954b2e63d5c5fcd09d995aa36faba39 100644 (file)
--- 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)
index d6230e7086b78a7fa6e1efdd7e601f31cd1cf21f..e3da3e37d0a7f7913eaf36b23ea44d743d87e47f 100644 (file)
@@ -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) {
index 6b555b66beb90e92e713314dfc313d65a0c8514f..3388c4c5feed5fc91651268f2520bf09e5546f83 100644 (file)
@@ -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 {
index 3bef3ccaec711c43e53708df0d8d8f081dd58251..5832eee4ce315953718794b4994a12504cd08c79 100644 (file)
@@ -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;
 
index beca868294a517e852ccd26584b11526e09e53f2..f0c1e37569bb3fd5555d1768ead2903cde4d3c19 100644 (file)
@@ -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;