Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/gomoku gomoku: fix lint warnings



details:   https://anonhg.NetBSD.org/src/rev/3db57a770733
branches:  trunk
changeset: 366160:3db57a770733
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 16 19:55:58 2022 +0000

description:
gomoku: fix lint warnings

Most warnings were about implicit conversions from ptrdiff_t to int; add
explicit cast for them, as they are far from overflowing int.

The casts from one pointer type to 'struct combostr **' were indeed
suspicious.  In these cases, a single region of memory is allocated to
store two objects of different type, without declaring a struct type for
their combination.  The second object is an array of variable size.

No binary change.

diffstat:

 games/gomoku/Makefile   |   4 +++-
 games/gomoku/bdinit.c   |   8 ++++----
 games/gomoku/bdisp.c    |  10 +++++-----
 games/gomoku/main.c     |   6 +++---
 games/gomoku/makemove.c |  14 +++++++-------
 games/gomoku/pickmove.c |  46 +++++++++++++++++++++++-----------------------
 6 files changed, 45 insertions(+), 43 deletions(-)

diffs (truncated from 358 to 300 lines):

diff -r 7e952f8d63cc -r 3db57a770733 games/gomoku/Makefile
--- a/games/gomoku/Makefile     Mon May 16 19:20:25 2022 +0000
+++ b/games/gomoku/Makefile     Mon May 16 19:55:58 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.5 2010/02/06 23:45:25 he Exp $
+#      $NetBSD: Makefile,v 1.6 2022/05/16 19:55:58 rillig Exp $
 #      @(#)Makefile    8.1 (Berkeley) 7/24/94
 
 PROG=  gomoku
@@ -8,4 +8,6 @@
 LDADD= -lcurses -lterminfo
 HIDEGAME=hidegame
 
+LINTFLAGS+=    -w      # treat warnings as errors
+
 .include <bsd.prog.mk>
diff -r 7e952f8d63cc -r 3db57a770733 games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c     Mon May 16 19:20:25 2022 +0000
+++ b/games/gomoku/bdinit.c     Mon May 16 19:55:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdinit.c,v 1.11 2022/05/15 22:56:20 rillig Exp $       */
+/*     $NetBSD: bdinit.c,v 1.12 2022/05/16 19:55:58 rillig Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)bdinit.c     8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: bdinit.c,v 1.11 2022/05/15 22:56:20 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.12 2022/05/16 19:55:58 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -133,7 +133,7 @@
                                if (sp->s_flags & (BFLAG << r))
                                        continue;
                                cbp->c_combo.s = sp->s_fval[BLACK][r].s;
-                               cbp->c_vertex = sp - board;
+                               cbp->c_vertex = (u_short)(sp - board);
                                cbp->c_nframes = 1;
                                cbp->c_dir = r;
                                sp->s_frame[r] = cbp;
@@ -213,7 +213,7 @@
                            break;
                        if (sp2->s_flags & bmask)
                            continue;
-                       n = sp2->s_frame[r] - frames;
+                       n = (int)(sp2->s_frame[r] - frames);
                        ip[n] = vertex;
                        str[n] |= (f == 5) ? mask & 0xA : mask;
                        if (r == cbp->c_dir) {
diff -r 7e952f8d63cc -r 3db57a770733 games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c      Mon May 16 19:20:25 2022 +0000
+++ b/games/gomoku/bdisp.c      Mon May 16 19:55:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdisp.c,v 1.22 2022/05/15 22:56:20 rillig Exp $        */
+/*     $NetBSD: bdisp.c,v 1.23 2022/05/16 19:55:58 rillig Exp $        */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)bdisp.c    8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: bdisp.c,v 1.22 2022/05/15 22:56:20 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.23 2022/05/16 19:55:58 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -134,8 +134,8 @@
 
        move(21, 0);
        printw("                                              ");
-       i = strlen(plyr[BLACK]);
-       j = strlen(plyr[WHITE]);
+       i = (int)strlen(plyr[BLACK]);
+       j = (int)strlen(plyr[WHITE]);
        if (i + j <= 20) {
                move(21, 10 - (i + j) / 2);
                printw("BLACK/%s (*) vs. WHITE/%s (O)",
@@ -248,7 +248,7 @@
 void
 ask(const char *str)
 {
-       int len = strlen(str);
+       int len = (int)strlen(str);
 
        move(BSZ + 4, 0);
        addstr(str);
diff -r 7e952f8d63cc -r 3db57a770733 games/gomoku/main.c
--- a/games/gomoku/main.c       Mon May 16 19:20:25 2022 +0000
+++ b/games/gomoku/main.c       Mon May 16 19:55:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.31 2022/05/15 22:56:20 rillig Exp $ */
+/*     $NetBSD: main.c,v 1.32 2022/05/16 19:55:58 rillig Exp $ */
 
 /*
  * Copyright (c) 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.31 2022/05/15 22:56:20 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.32 2022/05/16 19:55:58 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -141,7 +141,7 @@
        }
 
        if (!debug)
-               srandom(time(0));
+               srandom((unsigned int)time(0));
        if (interactive)
                cursinit();             /* initialize curses */
 again:
diff -r 7e952f8d63cc -r 3db57a770733 games/gomoku/makemove.c
--- a/games/gomoku/makemove.c   Mon May 16 19:20:25 2022 +0000
+++ b/games/gomoku/makemove.c   Mon May 16 19:55:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemove.c,v 1.13 2022/05/15 22:08:05 rillig Exp $     */
+/*     $NetBSD: makemove.c,v 1.14 2022/05/16 19:55:58 rillig Exp $     */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)makemove.c 8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: makemove.c,v 1.13 2022/05/15 22:08:05 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.14 2022/05/16 19:55:58 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -243,7 +243,7 @@
                 * do the rows 0 <= r1 <= r. The r1 == r case is special
                 * since the two frames can overlap at more than one point.
                 */
-               str = &overlap[(a = sp1->s_frame[r] - frames) * FAREA];
+               str = &overlap[(a = (int)(sp1->s_frame[r] - frames)) * FAREA];
                sp2 = sp1 - d;
                for (i = f + 1; i < 6; i++, sp2 -= d) {
                    if (sp2->s_occ == BORDER)
@@ -262,12 +262,12 @@
                            n++;
                        }
                    }
-                   b = sp2->s_frame[r] - frames;
+                   b = (int)(sp2->s_frame[r] - frames);
                    if (n == 0) {
                        if (sp->s_occ == EMPTY) {
                            str[b] &= 0xA;
                            overlap[b * FAREA + a] &= 0xC;
-                           intersect[a * FAREA + b] = n = sp - board;
+                           intersect[a * FAREA + b] = n = (int)(sp - board);
                            intersect[b * FAREA + a] = n;
                        } else {
                            str[b] = 0;
@@ -281,7 +281,7 @@
                            str[b] &= 0xF;
                            overlap[b * FAREA + a] &= 0xF;
                        }
-                       intersect[a * FAREA + b] = n = esp - board;
+                       intersect[a * FAREA + b] = n = (int)(esp - board);
                        intersect[b * FAREA + a] = n;
                    }
                    /* else no change, still multiple overlap */
@@ -297,7 +297,7 @@
                            break;
                        if (sp->s_flags & bmask1)
                            continue;
-                       b = sp->s_frame[r1] - frames;
+                       b = (int)(sp->s_frame[r1] - frames);
                        str[b] = 0;
                        overlap[b * FAREA + a] = 0;
                    }
diff -r 7e952f8d63cc -r 3db57a770733 games/gomoku/pickmove.c
--- a/games/gomoku/pickmove.c   Mon May 16 19:20:25 2022 +0000
+++ b/games/gomoku/pickmove.c   Mon May 16 19:55:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pickmove.c,v 1.28 2022/05/16 19:20:25 rillig Exp $     */
+/*     $NetBSD: pickmove.c,v 1.29 2022/05/16 19:55:58 rillig Exp $     */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: pickmove.c,v 1.28 2022/05/16 19:20:25 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.29 2022/05/16 19:55:58 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -128,7 +128,7 @@
                if (debug && (sp->s_combo[BLACK].c.a == 1 ||
                    sp->s_combo[WHITE].c.a == 1)) {
                        debuglog("- %s %x/%d %d %x/%d %d %d",
-                           stoc(sp - board),
+                           stoc((int)(sp - board)),
                            sp->s_combo[BLACK].s, sp->s_level[BLACK],
                            sp->s_nforce[BLACK],
                            sp->s_combo[WHITE].s, sp->s_level[WHITE],
@@ -145,13 +145,13 @@
 
        if (debug) {
                debuglog("B %s %x/%d %d %x/%d %d %d",
-                   stoc(sp1 - board),
+                   stoc((int)(sp1 - board)),
                    sp1->s_combo[BLACK].s, sp1->s_level[BLACK],
                    sp1->s_nforce[BLACK],
                    sp1->s_combo[WHITE].s, sp1->s_level[WHITE],
                    sp1->s_nforce[WHITE], sp1->s_wval);
                debuglog("W %s %x/%d %d %x/%d %d %d",
-                   stoc(sp2 - board),
+                   stoc((int)(sp2 - board)),
                    sp2->s_combo[WHITE].s, sp2->s_level[WHITE],
                    sp2->s_nforce[WHITE],
                    sp2->s_combo[BLACK].s, sp2->s_level[BLACK],
@@ -161,7 +161,7 @@
                 * all be blocked with one move.
                 */
                sp = (us == BLACK) ? sp2 : sp1;
-               m = sp - board;
+               m = (int)(sp - board);
                if (sp->s_combo[!us].c.a == 1 && !BIT_TEST(forcemap, m))
                        debuglog("*** Can't be blocked");
        }
@@ -182,8 +182,8 @@
         */
        if (Tcp->c.a <= 1 && (Ocp->c.a > 1 ||
            Tcp->c.a + Tcp->c.b < Ocp->c.a + Ocp->c.b))
-               return sp2 - board;
-       return sp1 - board;
+               return (int)(sp2 - board);
+       return (int)(sp1 - board);
 }
 
 /*
@@ -202,8 +202,8 @@
                return sp->s_nforce[us] > sp1->s_nforce[us];
 
        them = !us;
-       s = sp - board;
-       s1 = sp1 - board;
+       s = (int)(sp - board);
+       s1 = (int)(sp1 - board);
        if ((BIT_TEST(forcemap, s) != 0) != (BIT_TEST(forcemap, s1) != 0))
                return BIT_TEST(forcemap, s) != 0;
 
@@ -307,7 +307,7 @@
                        if (cp->s == 0x101) {
                                sp->s_nforce[color]++;
                                if (color != nextcolor) {
-                                       n = sp - board;
+                                       n = (int)(sp - board);
                                        BIT_SET(tmpmap, n);
                                }
                        }
@@ -334,6 +334,7 @@
         * Limit the search depth early in the game.
         */
        d = 2;
+       /* LINTED 117: bitwise '>>' on signed value possibly nonportable */
        while (d <= ((movenum + 1) >> 1) && combolen > n) {
                if (debug) {
                        debuglog("%cL%d %d %d %d", "BW"[color],
@@ -474,7 +475,7 @@
                    2 * sizeof(struct combostr *));
                if (ncbp == NULL)
                    panic("Out of memory!");
-               scbpp = (struct combostr **)(ncbp + 1);
+               scbpp = (void *)(ncbp + 1);
                fcbp = fsp->s_frame[r];
                if (ocbp < fcbp) {
                    scbpp[0] = ocbp;
@@ -491,7 +492,7 @@
                ncbp->c_linkv[1].s = fcb.s;
                ncbp->c_voff[0] = off;
                ncbp->c_voff[1] = f;
-               ncbp->c_vertex = osp - board;
+               ncbp->c_vertex = (u_short)(osp - board);
                ncbp->c_nframes = 2;
                ncbp->c_dir = 0;
                ncbp->c_frameindex = 0;
@@ -720,8 +721,8 @@
                (cbp->c_nframes + 1) * sizeof(struct combostr *));
            if (ncbp == NULL)
                panic("Out of memory!");
-           scbpp = (struct combostr **)(ncbp + 1);
-           if (sortcombo(scbpp, (struct combostr **)(cbp + 1), ocbp)) {
+           scbpp = (void *)(ncbp + 1);
+           if (sortcombo(scbpp, (void *)(cbp + 1), ocbp)) {
                free(ncbp);
                continue;
            }
@@ -733,7 +734,7 @@
            ncbp->c_link[1] = ocbp;
            ncbp->c_linkv[1].s = ocb.s;



Home | Main Index | Thread Index | Old Index