Module Name: src Committed By: dholland Date: Thu Jun 4 06:41:51 UTC 2009
Modified Files: src/games/gomoku: gomoku.h pickmove.c Log Message: Remove remaining references to sprintf. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/games/gomoku/gomoku.h cvs rdiff -u -r1.16 -r1.17 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/gomoku.h diff -u src/games/gomoku/gomoku.h:1.13 src/games/gomoku/gomoku.h:1.14 --- src/games/gomoku/gomoku.h:1.13 Thu Jun 4 06:27:47 2009 +++ src/games/gomoku/gomoku.h Thu Jun 4 06:41:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: gomoku.h,v 1.13 2009/06/04 06:27:47 dholland Exp $ */ +/* $NetBSD: gomoku.h,v 1.14 2009/06/04 06:41:50 dholland Exp $ */ /* * Copyright (c) 1994 @@ -290,7 +290,7 @@ void appendcombo(struct combostr *, int); void updatecombo(struct combostr *, int); void markcombo(struct combostr *); -void printcombo(struct combostr *, char *); +void printcombo(struct combostr *, char *, size_t); void makecombo(struct combostr *, struct spotstr *, int, int); void makecombo2(struct combostr *, struct spotstr *, int, int); int sortcombo(struct combostr **, struct combostr **, struct combostr *); Index: src/games/gomoku/pickmove.c diff -u src/games/gomoku/pickmove.c:1.16 src/games/gomoku/pickmove.c:1.17 --- src/games/gomoku/pickmove.c:1.16 Thu Jun 4 06:27:47 2009 +++ src/games/gomoku/pickmove.c Thu Jun 4 06:41:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: pickmove.c,v 1.16 2009/06/04 06:27:47 dholland Exp $ */ +/* $NetBSD: pickmove.c,v 1.17 2009/06/04 06:41:50 dholland 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.16 2009/06/04 06:27:47 dholland Exp $"); +__RCSID("$NetBSD: pickmove.c,v 1.17 2009/06/04 06:41:50 dholland Exp $"); #endif #endif /* not lint */ @@ -409,6 +409,7 @@ int baseB, fcnt, emask, bmask, n; union comboval ocb, fcb; struct combostr **scbpp, *fcbp; + char tmp[128]; /* try to combine a new frame with those found so far */ ocb.s = s; @@ -494,13 +495,13 @@ combocnt++; if ((c == 1 && debug > 1) || debug > 3) { - debuglog(fmtbuf, "%c c %d %d m %x %x o %d %d", + debuglog("%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]); - printcombo(ncbp, fmtbuf); - debuglog("%s", fmtbuf); + printcombo(ncbp, tmp, sizeof(tmp)); + debuglog("%s", tmp); } if (c > 1) { /* record the empty spots that will complete this combo */ @@ -641,6 +642,7 @@ int baseB, fcnt, emask, verts; union comboval ocb; struct overlap_info vertices[1]; + char tmp[128]; ocb.s = s; baseB = ocb.c.a + ocb.c.b - 1; @@ -744,8 +746,8 @@ ncbp->c_framecnt[0], ncbp->c_framecnt[1], ncbp->c_emask[0], ncbp->c_emask[1], ncbp->c_voff[0], ncbp->c_voff[1]); - printcombo(ncbp, fmtbuf); - debuglog("%s", fmtbuf); + printcombo(ncbp, tmp, sizeof(tmp)); + debuglog("%s", tmp); } if (c > 1) { /* record the empty spots that will complete this combo */ @@ -782,10 +784,11 @@ struct spotstr *sp; int s, d, m, emask, i; int nframes; + char tmp[128]; if (debug > 2) { - printcombo(ocbp, fmtbuf); - debuglog("E%c %s", "bw"[curcolor], fmtbuf); + printcombo(ocbp, tmp, sizeof(tmp)); + debuglog("E%c %s", "bw"[curcolor], tmp); } /* should never happen but check anyway */ @@ -1196,17 +1199,18 @@ #ifdef DEBUG if (debug > 3) { - char *str; + char buf[128]; + size_t pos; debuglog("sortc: %s%c l%d", stoc(fcbp->c_vertex), pdir[fcbp->c_dir], curlevel); - str = fmtbuf; + pos = 0; for (cpp = cbpp; cpp < cbpp + curlevel; cpp++) { - sprintf(str, " %s%c", stoc((*cpp)->c_vertex), - pdir[(*cpp)->c_dir]); - str += strlen(str); + snprintf(buf + pos, sizeof(buf) - pos, " %s%c", + stoc((*cpp)->c_vertex), pdir[(*cpp)->c_dir]); + pos += strlen(buf + pos); } - debuglog("%s", fmtbuf); + debuglog("%s", buf); } #endif /* DEBUG */ @@ -1254,26 +1258,29 @@ /* we found a match */ #ifdef DEBUG if (debug > 3) { - char *str; + char buf[128]; + size_t pos; debuglog("sort1: n%d", n); - str = fmtbuf; + pos = 0; for (cpp = scbpp; cpp < scbpp + n; cpp++) { - sprintf(str, " %s%c", stoc((*cpp)->c_vertex), + snprintf(buf + pos, sizeof(buf) - pos, " %s%c", + stoc((*cpp)->c_vertex), pdir[(*cpp)->c_dir]); - str += strlen(str); + pos += strlen(buf + pos); } - debuglog("%s", fmtbuf); - printcombo(cbp, fmtbuf); - debuglog("%s", fmtbuf); - str = fmtbuf; + debuglog("%s", buf); + printcombo(cbp, buf, sizeof(buf)); + debuglog("%s", buf); cbpp--; + pos = 0; for (cpp = cbpp; cpp < cbpp + n; cpp++) { - sprintf(str, " %s%c", stoc((*cpp)->c_vertex), + snprintf(buf + pos, sizeof(buf) - pos, " %s%c", + stoc((*cpp)->c_vertex), pdir[(*cpp)->c_dir]); - str += strlen(str); + pos += strlen(buf + pos); } - debuglog("%s", fmtbuf); + debuglog("%s", buf); } #endif /* DEBUG */ return (1); @@ -1294,21 +1301,25 @@ } /* - * Print the combo into string 'str'. + * Print the combo into string buffer 'buf'. */ void -printcombo(struct combostr *cbp, char *str) +printcombo(struct combostr *cbp, char *buf, size_t max) { struct combostr *tcbp; + size_t pos = 0; + + snprintf(buf + pos, max - pos, "%x/%d", + cbp->c_combo.s, cbp->c_nframes); + pos += strlen(buf + pos); - sprintf(str, "%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], - cbp->c_flags); - str += strlen(str); + snprintf(buf + pos, max - pos, " %s%c%x", + stoc(tcbp->c_vertex), pdir[tcbp->c_dir], cbp->c_flags); + pos += strlen(buf + pos); } - sprintf(str, " %s%c", stoc(cbp->c_vertex), pdir[cbp->c_dir]); + snprintf(buf + pos, max - pos, " %s%c", + stoc(cbp->c_vertex), pdir[cbp->c_dir]); } #ifdef DEBUG