summaryrefslogtreecommitdiff
path: root/games/gomoku
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-04-06 18:50:39 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-04-06 18:50:39 +0000
commit0f64621783b3f46a4851826b9f4284e3c9dbeb61 (patch)
tree352fcb09d9321309ec519dc3144147a24bd64bda /games/gomoku
parent997f28507be542389b846c45806474af6bbfdedc (diff)
2451 lines of strdup/sprintf/strcpy whacking. mostly ok'd by pjanzen
already, but he may have later changes to make still.
Diffstat (limited to 'games/gomoku')
-rw-r--r--games/gomoku/gomoku.h6
-rw-r--r--games/gomoku/main.c24
-rw-r--r--games/gomoku/pickmove.c70
-rw-r--r--games/gomoku/stoc.c6
4 files changed, 65 insertions, 41 deletions
diff --git a/games/gomoku/gomoku.h b/games/gomoku/gomoku.h
index a19f098c6a9..bdff4c2c85f 100644
--- a/games/gomoku/gomoku.h
+++ b/games/gomoku/gomoku.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: gomoku.h,v 1.6 2002/02/17 19:42:20 millert Exp $ */
+/* $OpenBSD: gomoku.h,v 1.7 2003/04/06 18:50:37 deraadt Exp $ */
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
@@ -254,7 +254,7 @@ struct ovlp_info {
};
extern char *letters;
-extern char fmtbuf[];
+extern char fmtbuf[128];
extern char pdir[];
extern int dd[4];
@@ -305,7 +305,7 @@ void markcombo(struct combostr *);
#endif
void panic(char *);
int pickmove(int);
-void printcombo(struct combostr *, char *);
+void printcombo(struct combostr *, char *, size_t);
void qlog(char *);
void quit(int);
int readinput(FILE *);
diff --git a/games/gomoku/main.c b/games/gomoku/main.c
index 505f5eecc4e..a14cfeacb10 100644
--- a/games/gomoku/main.c
+++ b/games/gomoku/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.13 2002/12/06 21:48:51 millert Exp $ */
+/* $OpenBSD: main.c,v 1.14 2003/04/06 18:50:37 deraadt Exp $ */
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
@@ -45,7 +45,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.13 2002/12/06 21:48:51 millert Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.14 2003/04/06 18:50:37 deraadt Exp $";
#endif
#endif /* not lint */
@@ -193,7 +193,7 @@ again:
else if (strcmp(buf, "white") == 0)
color = WHITE;
else {
- sprintf(fmtbuf,
+ snprintf(fmtbuf, sizeof fmtbuf,
"Huh? Expected `black' or `white', got `%s'\n",
buf);
panic(fmtbuf);
@@ -299,7 +299,8 @@ again:
break;
}
if (interactive) {
- sprintf(fmtbuf, fmt[color], movenum, stoc(curmove));
+ snprintf(fmtbuf, sizeof fmtbuf,
+ fmt[color], movenum, stoc(curmove));
log(fmtbuf);
}
if ((i = makemove(color, curmove)) != MOVEOK)
@@ -397,7 +398,8 @@ top:
quit(0);
case 'd': /* set debug level */
debug = fmtbuf[1] - '0';
- sprintf(fmtbuf, "Debug set to %d", debug);
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "Debug set to %d", debug);
dlog(fmtbuf);
sleep(1);
case 'c':
@@ -411,7 +413,8 @@ top:
goto top;
case 's': /* suggest a move */
i = fmtbuf[1] == 'b' ? BLACK : WHITE;
- sprintf(fmtbuf, "suggest %c %s", i == BLACK ? 'B' : 'W',
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "suggest %c %s", i == BLACK ? 'B' : 'W',
stoc(pickmove(i)));
dlog(fmtbuf);
goto top;
@@ -466,17 +469,20 @@ top:
goto top;
case 'p':
sp = &board[i = ctos(fmtbuf + 1)];
- sprintf(fmtbuf, "V %s %x/%d %d %x/%d %d %d %x", stoc(i),
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "V %s %x/%d %d %x/%d %d %d %x", stoc(i),
sp->s_combo[BLACK].s, sp->s_level[BLACK],
sp->s_nforce[BLACK],
sp->s_combo[WHITE].s, sp->s_level[WHITE],
sp->s_nforce[WHITE], sp->s_wval, sp->s_flg);
dlog(fmtbuf);
- sprintf(fmtbuf, "FB %s %x %x %x %x", stoc(i),
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "FB %s %x %x %x %x", stoc(i),
sp->s_fval[BLACK][0].s, sp->s_fval[BLACK][1].s,
sp->s_fval[BLACK][2].s, sp->s_fval[BLACK][3].s);
dlog(fmtbuf);
- sprintf(fmtbuf, "FW %s %x %x %x %x", stoc(i),
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "FW %s %x %x %x %x", stoc(i),
sp->s_fval[WHITE][0].s, sp->s_fval[WHITE][1].s,
sp->s_fval[WHITE][2].s, sp->s_fval[WHITE][3].s);
dlog(fmtbuf);
diff --git a/games/gomoku/pickmove.c b/games/gomoku/pickmove.c
index bf3f07c7b45..fe42b537e03 100644
--- a/games/gomoku/pickmove.c
+++ b/games/gomoku/pickmove.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pickmove.c,v 1.7 2002/05/31 04:21:30 pjanzen Exp $ */
+/* $OpenBSD: pickmove.c,v 1.8 2003/04/06 18:50:37 deraadt Exp $ */
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95";
#else
-static char rcsid[] = "$OpenBSD: pickmove.c,v 1.7 2002/05/31 04:21:30 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: pickmove.c,v 1.8 2003/04/06 18:50:37 deraadt Exp $";
#endif
#endif /* not lint */
@@ -102,7 +102,8 @@ pickmove(us)
continue;
if (debug && (sp->s_combo[BLACK].c.a == 1 ||
sp->s_combo[WHITE].c.a == 1)) {
- sprintf(fmtbuf, "- %s %x/%d %d %x/%d %d %d", stoc(sp - board),
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "- %s %x/%d %d %x/%d %d %d", stoc(sp - board),
sp->s_combo[BLACK].s, sp->s_level[BLACK],
sp->s_nforce[BLACK],
sp->s_combo[WHITE].s, sp->s_level[WHITE],
@@ -119,14 +120,16 @@ pickmove(us)
}
if (debug) {
- sprintf(fmtbuf, "B %s %x/%d %d %x/%d %d %d",
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "B %s %x/%d %d %x/%d %d %d",
stoc(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);
dlog(fmtbuf);
- sprintf(fmtbuf, "W %s %x/%d %d %x/%d %d %d",
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "W %s %x/%d %d %x/%d %d %d",
stoc(sp2 - board),
sp2->s_combo[WHITE].s, sp2->s_level[WHITE],
sp2->s_nforce[WHITE],
@@ -335,7 +338,8 @@ scanframes(color)
d = 2;
while (d <= ((unsigned)(movenum + 1) >> 1) && combolen > n) {
if (debug) {
- sprintf(fmtbuf, "%cL%d %d %d %d", "BW"[color],
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "%cL%d %d %d %d", "BW"[color],
d, combolen - n, combocnt, elistcnt);
dlog(fmtbuf);
refresh();
@@ -394,13 +398,15 @@ scanframes(color)
#ifdef DEBUG
if (combocnt) {
- sprintf(fmtbuf, "scanframes: %c combocnt %d", "BW"[color],
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "scanframes: %c combocnt %d", "BW"[color],
combocnt);
dlog(fmtbuf);
whatsup(0);
}
if (elistcnt) {
- sprintf(fmtbuf, "scanframes: %c elistcnt %d", "BW"[color],
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "scanframes: %c elistcnt %d", "BW"[color],
elistcnt);
dlog(fmtbuf);
whatsup(0);
@@ -510,13 +516,14 @@ makecombo2(ocbp, osp, off, s)
combocnt++;
if (c == 1 && debug > 1) {
- sprintf(fmtbuf, "%c c %d %d m %x %x o %d %d",
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "%c c %d %d m %x %x o %d %d",
"bw"[curcolor],
ncbp->c_framecnt[0], ncbp->c_framecnt[1],
ncbp->c_emask[0], ncbp->c_emask[1],
ncbp->c_voff[0], ncbp->c_voff[1]);
dlog(fmtbuf);
- printcombo(ncbp, fmtbuf);
+ printcombo(ncbp, fmtbuf, sizeof fmtbuf);
dlog(fmtbuf);
}
if (c > 1) {
@@ -680,7 +687,8 @@ makecombo(ocbp, osp, off, s)
sp = &board[vertices[0].o_intersect];
#ifdef DEBUG
if (sp->s_occ != EMPTY) {
- sprintf(fmtbuf, "loop: %c %s", "BW"[curcolor],
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "loop: %c %s", "BW"[curcolor],
stoc(sp - board));
dlog(fmtbuf);
whatsup(0);
@@ -762,13 +770,14 @@ makecombo(ocbp, osp, off, s)
}
if (c == 1 && debug > 1) {
- sprintf(fmtbuf, "%c v%d i%d d%d c %d %d m %x %x o %d %d",
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "%c v%d i%d d%d c %d %d m %x %x o %d %d",
"bw"[curcolor], verts, ncbp->c_frameindex, ncbp->c_dir,
ncbp->c_framecnt[0], ncbp->c_framecnt[1],
ncbp->c_emask[0], ncbp->c_emask[1],
ncbp->c_voff[0], ncbp->c_voff[1]);
dlog(fmtbuf);
- printcombo(ncbp, fmtbuf);
+ printcombo(ncbp, fmtbuf, sizeof fmtbuf);
dlog(fmtbuf);
}
if (c > 1) {
@@ -809,8 +818,8 @@ makeempty(ocbp)
int nframes;
if (debug > 2) {
- sprintf(fmtbuf, "E%c ", "bw"[curcolor]);
- printcombo(ocbp, fmtbuf + 3);
+ snprintf(fmtbuf, sizeof fmtbuf, "E%c ", "bw"[curcolor]);
+ printcombo(ocbp, fmtbuf + 3, sizeof fmtbuf - 3);
dlog(fmtbuf);
}
@@ -932,7 +941,8 @@ makeempty(ocbp)
}
nep->e_fval.s = ep->e_fval.s;
if (debug > 2) {
- sprintf(fmtbuf, "e %s o%d i%d c%d m%x %x",
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "e %s o%d i%d c%d m%x %x",
stoc(sp - board),
nep->e_off,
nep->e_frameindex,
@@ -1228,12 +1238,14 @@ sortcombo(scbpp, cbpp, fcbp)
if (debug > 3) {
char *str;
- sprintf(fmtbuf, "sortc: %s%c l%d", stoc(fcbp->c_vertex),
+ snprintf(fmtbuf, sizeof fmtbuf,
+ "sortc: %s%c l%d", stoc(fcbp->c_vertex),
pdir[fcbp->c_dir], curlevel);
dlog(fmtbuf);
str = fmtbuf;
for (cpp = cbpp; cpp < cbpp + curlevel; cpp++) {
- sprintf(str, " %s%c", stoc((*cpp)->c_vertex),
+ snprintf(str, fmtbuf + sizeof fmtbut - str,
+ " %s%c", stoc((*cpp)->c_vertex),
pdir[(*cpp)->c_dir]);
str += strlen(str);
}
@@ -1287,21 +1299,23 @@ inserted:
if (debug > 3) {
char *str;
- sprintf(fmtbuf, "sort1: n%d", n);
+ snprintf(fmtbuf, sizeof fmtbuf, "sort1: n%d", n);
dlog(fmtbuf);
str = fmtbuf;
for (cpp = scbpp; cpp < scbpp + n; cpp++) {
- sprintf(str, " %s%c", stoc((*cpp)->c_vertex),
+ snprintf(str, fmtbuf + sizeof fmtbuf - str,
+ " %s%c", stoc((*cpp)->c_vertex),
pdir[(*cpp)->c_dir]);
str += strlen(str);
}
dlog(fmtbuf);
- printcombo(cbp, fmtbuf);
+ printcombo(cbp, fmtbuf, sizeof fmtbuf);
dlog(fmtbuf);
str = fmtbuf;
cbpp--;
for (cpp = cbpp; cpp < cbpp + n; cpp++) {
- sprintf(str, " %s%c", stoc((*cpp)->c_vertex),
+ snprintf(str, fmtbuf + sizeof fmtbuf - str,
+ " %s%c", stoc((*cpp)->c_vertex),
pdir[(*cpp)->c_dir]);
str += strlen(str);
}
@@ -1329,20 +1343,24 @@ inserted:
* Print the combo into string 'str'.
*/
void
-printcombo(cbp, str)
+printcombo(cbp, str, strl)
struct combostr *cbp;
char *str;
+ size_t strl;
{
+ char *basestr = str;
struct combostr *tcbp;
- sprintf(str, "%x/%d", cbp->c_combo.s, cbp->c_nframes);
+ snprintf(str, strl, "%x/%d", cbp->c_combo.s, cbp->c_nframes);
str += strlen(str);
for (; (tcbp = cbp->c_link[1]) != NULL; cbp = cbp->c_link[0]) {
- sprintf(str, " %s%c%x", stoc(tcbp->c_vertex), pdir[tcbp->c_dir],
+ snprintf(str, basestr + strl - str,
+ " %s%c%x", stoc(tcbp->c_vertex), pdir[tcbp->c_dir],
cbp->c_flg);
str += strlen(str);
}
- sprintf(str, " %s%c", stoc(cbp->c_vertex), pdir[cbp->c_dir]);
+ snprintf(str, basestr + strl - str,
+ " %s%c", stoc(cbp->c_vertex), pdir[cbp->c_dir]);
}
#ifdef DEBUG
diff --git a/games/gomoku/stoc.c b/games/gomoku/stoc.c
index 9b16713300a..be736f25b58 100644
--- a/games/gomoku/stoc.c
+++ b/games/gomoku/stoc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stoc.c,v 1.4 2002/05/31 04:21:30 pjanzen Exp $ */
+/* $OpenBSD: stoc.c,v 1.5 2003/04/06 18:50:37 deraadt Exp $ */
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)stoc.c 8.1 (Berkeley) 7/24/94";
#else
-static char rcsid[] = "$OpenBSD: stoc.c,v 1.4 2002/05/31 04:21:30 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: stoc.c,v 1.5 2003/04/06 18:50:37 deraadt Exp $";
#endif
#endif /* not lint */
@@ -73,7 +73,7 @@ stoc(s)
for (i = 0; mv[i].m_code >= 0; i++)
if (s == mv[i].m_code)
return(mv[i].m_text);
- sprintf(buf, "%c%d", letters[s % BSZ1], s / BSZ1);
+ snprintf(buf, sizeof buf, "%c%d", letters[s % BSZ1], s / BSZ1);
return(buf);
}