]> granicus.if.org Git - nethack/commitdiff
fix more clang complaints
authorPatR <rankin@nethack.org>
Sat, 21 Nov 2015 08:25:50 +0000 (00:25 -0800)
committerPatR <rankin@nethack.org>
Sat, 21 Nov 2015 08:25:50 +0000 (00:25 -0800)
Fix some more of the complaints from clang's static analyzer.  The one
in options.c (manipulating warnings symbols) appears to be an actual bug.
All the rest are either because the analysis isn't quite sophicated
enough or outright bogus.

Two of them appear to be because a static routine is attempting to guard
against callers in the same file failing to pass in required output
pointers.  Stripping away the check for missing pointer should convince
the analyzer that those output parameters always receive a value.  We'll
see once the analysis is eventually re-run....

src/end.c
src/options.c
src/shknam.c
src/sp_lev.c
src/trap.c

index 5e1fd0b01c0af8a9229549a6bed3dcb1af9ce861..111766f44237d9f736a6c4e3c18e825b36ccceca 100644 (file)
--- a/src/end.c
+++ b/src/end.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 end.c   $NHDT-Date: 1447576343 2015/11/15 08:32:23 $  $NHDT-Branch: master $:$NHDT-Revision: 1.103 $ */
+/* NetHack 3.6 end.c   $NHDT-Date: 1448094339 2015/11/21 08:25:39 $  $NHDT-Branch: master $:$NHDT-Revision: 1.105 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -588,14 +588,15 @@ int category;
 char *defquery;
 {
     int idx;
-    char *dop = index(disclosure_options, category);
+    char *dop;
 
-    if (dop && defquery) {
+    *defquery = 'n';
+    if ((dop = index(disclosure_options, category)) != 0) {
         idx = (int) (dop - disclosure_options);
-        if (idx < 0 || idx > (NUM_DISCLOSURE_OPTIONS - 1)) {
+        if (idx < 0 || idx >= NUM_DISCLOSURE_OPTIONS) {
             impossible(
-                "should_query_disclose_option: bad disclosure index %d %c",
-                idx, category);
+                   "should_query_disclose_option: bad disclosure index %d %c",
+                       idx, category);
             *defquery = DISCLOSE_PROMPT_DEFAULT_YES;
             return TRUE;
         }
@@ -613,10 +614,7 @@ char *defquery;
             return TRUE;
         }
     }
-    if (defquery)
-        impossible("should_query_disclose_option: bad category %c", category);
-    else
-        impossible("should_query_disclose_option: null defquery");
+    impossible("should_query_disclose_option: bad category %c", category);
     return TRUE;
 }
 
@@ -625,7 +623,7 @@ disclose(how, taken)
 int how;
 boolean taken;
 {
-    char c = 0, defquery;
+    char c = '\0', defquery;
     char qbuf[QBUFSZ];
     boolean ask = FALSE;
 
@@ -1432,8 +1430,8 @@ boolean ask;
      */
     if (ntypes != 0) {
         c = ask ? yn_function(
-                      "Do you want an account of creatures vanquished?",
-                      ynqchars, defquery)
+                            "Do you want an account of creatures vanquished?",
+                              ynqchars, defquery)
                 : defquery;
         if (c == 'q')
             done_stopprint++;
@@ -1611,7 +1609,6 @@ int id;
         if (k->id == id)
             break;
     }
-
     return k;
 }
 
index 7772dcf513348ff0ee6a672397ecb0b33eb9555a..91a9700b33ee34b4050254e418c9a2d02e02fbcc 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 options.c       $NHDT-Date: 1447234076 2015/11/11 09:27:56 $  $NHDT-Branch: master $:$NHDT-Revision: 1.240 $ */
+/* NetHack 3.6 options.c       $NHDT-Date: 1448094341 2015/11/21 08:25:41 $  $NHDT-Branch: master $:$NHDT-Revision: 1.241 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1015,20 +1015,19 @@ warning_opts(opts, optype)
 register char *opts;
 const char *optype;
 {
-    uchar translate[MAXPCHARS + 1];
+    uchar translate[WARNCOUNT];
     int length, i;
 
     if (!(opts = string_for_env_opt(optype, opts, FALSE)))
         return;
     escapes(opts, opts);
 
-    length = strlen(opts);
-    if (length > WARNCOUNT)
-        length = WARNCOUNT;
+    length = (int) strlen(opts);
     /* match the form obtained from PC configuration files */
-    for (i = 0; i < length; i++)
-        translate[i] = (((i < WARNCOUNT) && opts[i]) ? (uchar) opts[i]
-                                                     : def_warnsyms[i].sym);
+    for (i = 0; i < WARNCOUNT; i++)
+        translate[i] = (i >= length) ? 0
+                                     : opts[i] ? (uchar) opts[i]
+                                               : def_warnsyms[i].sym;
     assign_warnings(translate);
 }
 
index ae6d3d68bada17950cc3ed217de0259d9c56b068..728976cba1b01947f05d167003e9f3f0b052a1c8 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 shknam.c        $NHDT-Date: 1446887533 2015/11/07 09:12:13 $  $NHDT-Branch: master $:$NHDT-Revision: 1.37 $ */
+/* NetHack 3.6 shknam.c        $NHDT-Date: 1448094342 2015/11/21 08:25:42 $  $NHDT-Branch: master $:$NHDT-Revision: 1.38 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -186,10 +186,9 @@ static const char *const shkhealthfoods[] = {
 
 /*
  * To add new shop types, all that is necessary is to edit the shtypes[]
- * array.
- * See mkroom.h for the structure definition.  Typically, you'll have to lower
- * some or all of the probability fields in old entries to free up some
- * percentage for the new type.
+ * array.  See mkroom.h for the structure definition.  Typically, you'll
+ * have to lower some or all of the probability fields in old entries to
+ * free up some percentage for the new type.
  *
  * The placement type field is not yet used but will be in the near future.
  *
@@ -200,7 +199,6 @@ static const char *const shkhealthfoods[] = {
  * In the latter case, prepend it with a unary minus so the code can know
  * (by testing the sign) whether to use mkobj() or mksobj().
  */
-
 const struct shclass shtypes[] = {
     { "general store",
       RANDOM_CLASS,
@@ -407,6 +405,7 @@ shkveg()
     int ok[NUM_OBJECTS];
 
     j = maxprob = 0;
+    ok[0] = 0; /* lint suppression */
     for (i = bases[(int) oclass]; i < NUM_OBJECTS; ++i) {
         if (objects[i].oc_class != oclass)
             break;
@@ -735,7 +734,8 @@ register struct mkroom *sroom;
         for (sx = sroom->lx; sx <= sroom->hx; sx++)
             for (sy = sroom->ly; sy <= sroom->hy; sy++) {
                 if (sroom->irregular) {
-                    if (levl[sx][sy].edge || (int) levl[sx][sy].roomno != rmno
+                    if (levl[sx][sy].edge
+                        || (int) levl[sx][sy].roomno != rmno
                         || distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1)
                         continue;
                 } else if ((sx == sroom->lx && doors[sh].x == sx - 1)
@@ -752,7 +752,8 @@ register struct mkroom *sroom;
     for (sx = sroom->lx; sx <= sroom->hx; sx++)
         for (sy = sroom->ly; sy <= sroom->hy; sy++) {
             if (sroom->irregular) {
-                if (levl[sx][sy].edge || (int) levl[sx][sy].roomno != rmno
+                if (levl[sx][sy].edge
+                    || (int) levl[sx][sy].roomno != rmno
                     || distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1)
                     continue;
             } else if ((sx == sroom->lx && doors[sh].x == sx - 1)
index 3388c4c5feed5fc91651268f2520bf09e5546f83..659e6a16ffa8280077ca4faff843e73fe8c508e6 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 sp_lev.c        $NHDT-Date: 1447836300 2015/11/18 08:45:00 $  $NHDT-Branch: master $:$NHDT-Revision: 1.73 $ */
+/* NetHack 3.6 sp_lev.c        $NHDT-Date: 1448094343 2015/11/21 08:25:43 $  $NHDT-Branch: master $:$NHDT-Revision: 1.75 $ */
 /*      Copyright (c) 1989 by Jean-Christophe Collet */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -23,8 +23,8 @@ typedef void FDECL((*select_iter_func), (int, int, genericptr_t));
 extern void FDECL(mkmap, (lev_init *));
 
 STATIC_DCL void FDECL(get_room_loc, (schar *, schar *, struct mkroom *));
-STATIC_DCL void FDECL(get_free_room_loc,
-                      (schar *, schar *, struct mkroom *, packed_coord));
+STATIC_DCL void FDECL(get_free_room_loc, (schar *, schar *,
+                                          struct mkroom *, packed_coord));
 STATIC_DCL void FDECL(create_trap, (trap *, struct mkroom *));
 STATIC_DCL int FDECL(noncoalignment, (ALIGNTYP_P));
 STATIC_DCL boolean FDECL(m_bad_boulder_spot, (int, int));
@@ -976,9 +976,6 @@ 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 a0ca296ea41faa9d66e0087fb42032f4bedf6044..495525045e57127bf48bfce2f528816765d444e4 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 trap.c  $NHDT-Date: 1448073071 2015/11/21 02:31:11 $  $NHDT-Branch: master $:$NHDT-Revision: 1.247 $ */
+/* NetHack 3.6 trap.c  $NHDT-Date: 1448094344 2015/11/21 08:25:44 $  $NHDT-Branch: master $:$NHDT-Revision: 1.248 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -3781,6 +3781,7 @@ struct trap *ttmp;
     xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy;
     boolean unused;
 
+    bx = by = cx = cy = 0; /* lint suppression */
     /* we know there's no monster in the way, and we're not trapped */
     if (!Punished
         || drag_ball(x, y, &bc, &bx, &by, &cx, &cy, &unused, TRUE)) {