Module Name: src Committed By: rillig Date: Mon May 16 19:55:58 UTC 2022
Modified Files: src/games/gomoku: Makefile bdinit.c bdisp.c main.c makemove.c pickmove.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/games/gomoku/Makefile cvs rdiff -u -r1.11 -r1.12 src/games/gomoku/bdinit.c cvs rdiff -u -r1.22 -r1.23 src/games/gomoku/bdisp.c cvs rdiff -u -r1.31 -r1.32 src/games/gomoku/main.c cvs rdiff -u -r1.13 -r1.14 src/games/gomoku/makemove.c cvs rdiff -u -r1.28 -r1.29 src/games/gomoku/pickmove.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/games/gomoku/Makefile diff -u src/games/gomoku/Makefile:1.5 src/games/gomoku/Makefile:1.6 --- src/games/gomoku/Makefile:1.5 Sat Feb 6 23:45:25 2010 +++ src/games/gomoku/Makefile Mon May 16 19:55:58 2022 @@ -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 @@ DPADD= ${LIBCURSES} ${LIBTERMINFO} LDADD= -lcurses -lterminfo HIDEGAME=hidegame +LINTFLAGS+= -w # treat warnings as errors + .include <bsd.prog.mk> Index: src/games/gomoku/bdinit.c diff -u src/games/gomoku/bdinit.c:1.11 src/games/gomoku/bdinit.c:1.12 --- src/games/gomoku/bdinit.c:1.11 Sun May 15 22:56:20 2022 +++ src/games/gomoku/bdinit.c Mon May 16 19:55:58 2022 @@ -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 @@ bdinit(struct spotstr *bp) 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 @@ init_overlap(void) 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) { Index: src/games/gomoku/bdisp.c diff -u src/games/gomoku/bdisp.c:1.22 src/games/gomoku/bdisp.c:1.23 --- src/games/gomoku/bdisp.c:1.22 Sun May 15 22:56:20 2022 +++ src/games/gomoku/bdisp.c Mon May 16 19:55:58 2022 @@ -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 @@ bdwho(int update) 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 @@ dislog(const char *str) void ask(const char *str) { - int len = strlen(str); + int len = (int)strlen(str); move(BSZ + 4, 0); addstr(str); Index: src/games/gomoku/main.c diff -u src/games/gomoku/main.c:1.31 src/games/gomoku/main.c:1.32 --- src/games/gomoku/main.c:1.31 Sun May 15 22:56:20 2022 +++ src/games/gomoku/main.c Mon May 16 19:55:58 2022 @@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1994\ #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 @@ main(int argc, char **argv) } if (!debug) - srandom(time(0)); + srandom((unsigned int)time(0)); if (interactive) cursinit(); /* initialize curses */ again: Index: src/games/gomoku/makemove.c diff -u src/games/gomoku/makemove.c:1.13 src/games/gomoku/makemove.c:1.14 --- src/games/gomoku/makemove.c:1.13 Sun May 15 22:08:05 2022 +++ src/games/gomoku/makemove.c Mon May 16 19:55:58 2022 @@ -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 @@ update_overlap(struct spotstr *osp) * 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 @@ update_overlap(struct spotstr *osp) 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 @@ update_overlap(struct spotstr *osp) 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 @@ update_overlap(struct spotstr *osp) 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; } Index: src/games/gomoku/pickmove.c diff -u src/games/gomoku/pickmove.c:1.28 src/games/gomoku/pickmove.c:1.29 --- src/games/gomoku/pickmove.c:1.28 Mon May 16 19:20:25 2022 +++ src/games/gomoku/pickmove.c Mon May 16 19:55:58 2022 @@ -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 @@ pickmove(int us) 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 @@ pickmove(int us) 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 @@ pickmove(int us) * 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 @@ pickmove(int us) */ 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 @@ better(const struct spotstr *sp, const s 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 @@ scanframes(int color) 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 @@ scanframes(int color) * 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 @@ makecombo2(struct combostr *ocbp, struct 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 @@ makecombo2(struct combostr *ocbp, struct 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 @@ makecombo(struct combostr *ocbp, struct (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 @@ makecombo(struct combostr *ocbp, struct ncbp->c_link[1] = ocbp; ncbp->c_linkv[1].s = ocb.s; ncbp->c_voff[1] = off; - ncbp->c_vertex = osp - board; + ncbp->c_vertex = (u_short)(osp - board); ncbp->c_nframes = cbp->c_nframes + 1; ncbp->c_flags = ocb.c.b ? C_OPEN_1 : 0; ncbp->c_frameindex = ep->e_frameindex; @@ -932,7 +933,7 @@ makeempty(struct combostr *ocbp) nep->e_fval.s = ep->e_fval.s; if (debug > 2) { debuglog("e %s o%d i%d c%d m%x %x", - stoc(sp - board), + stoc((int)(sp - board)), nep->e_off, nep->e_frameindex, nep->e_framecnt, @@ -1089,7 +1090,7 @@ checkframes(struct combostr *cbp, struct fcnt = cb.c.a - 2; verts = 0; myindex = cbp->c_nframes; - n = (fcbp - frames) * FAREA; + n = (int)(fcbp - frames) * FAREA; str = &overlap[n]; ip = &intersect[n]; /* @@ -1249,21 +1250,20 @@ sortcombo(struct combostr **scbpp, struc inserted: /* now check to see if this list of frames has already been seen */ - cbp = hashcombos[inx = *scbpp - frames]; + cbp = hashcombos[inx = (int)(*scbpp - frames)]; if (cbp == (struct combostr *)0) { /* * Easy case, this list hasn't been seen. * Add it to the hash list. */ - fcbp = (struct combostr *) - ((char *)scbpp - sizeof(struct combostr)); + fcbp = (void *)((char *)scbpp - sizeof(struct combostr)); hashcombos[inx] = fcbp; fcbp->c_next = fcbp->c_prev = fcbp; return 0; } ecbp = cbp; do { - cbpp = (struct combostr **)(cbp + 1); + cbpp = (void *)(cbp + 1); cpp = cbpp + n; spp = scbpp + n; cbpp++; /* first frame is always the same */ @@ -1308,7 +1308,7 @@ inserted: * Add it to the hash list. */ ecbp = cbp->c_prev; - fcbp = (struct combostr *)((char *)scbpp - sizeof(struct combostr)); + fcbp = (void *)((char *)scbpp - sizeof(struct combostr)); fcbp->c_next = cbp; fcbp->c_prev = ecbp; cbp->c_prev = fcbp;