summaryrefslogtreecommitdiffstats
path: root/gomoku
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2009-06-04 06:47:36 +0000
committerdholland <dholland@NetBSD.org>2009-06-04 06:47:36 +0000
commit5201ca857aeecdabe4e03794af0461e574dddbca (patch)
tree2bf26903bab35569f004dd64d1c0e2d10242371d /gomoku
parent92f1b6ea9c2921a6cbe51be12d242d1bb40b1995 (diff)
downloadbsdgames-darwin-5201ca857aeecdabe4e03794af0461e574dddbca.tar.gz
bsdgames-darwin-5201ca857aeecdabe4e03794af0461e574dddbca.tar.zst
bsdgames-darwin-5201ca857aeecdabe4e03794af0461e574dddbca.zip
Remove global scratch string buffer. Don't zoom off the end while reading
user input, either.
Diffstat (limited to 'gomoku')
-rw-r--r--gomoku/gomoku.h3
-rw-r--r--gomoku/main.c18
2 files changed, 10 insertions, 11 deletions
diff --git a/gomoku/gomoku.h b/gomoku/gomoku.h
index 5f2382fb..87229e10 100644
--- a/gomoku/gomoku.h
+++ b/gomoku/gomoku.h
@@ -1,4 +1,4 @@
-/* $NetBSD: gomoku.h,v 1.14 2009/06/04 06:41:50 dholland Exp $ */
+/* $NetBSD: gomoku.h,v 1.15 2009/06/04 06:47:36 dholland Exp $ */
/*
* Copyright (c) 1994
@@ -246,7 +246,6 @@ struct overlap_info {
};
extern const char *letters;
-extern char fmtbuf[];
extern const char pdir[];
extern const int dd[4];
diff --git a/gomoku/main.c b/gomoku/main.c
index 3f19106a..2789416b 100644
--- a/gomoku/main.c
+++ b/gomoku/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.16 2009/06/04 06:27:47 dholland Exp $ */
+/* $NetBSD: main.c,v 1.17 2009/06/04 06:47:36 dholland 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.16 2009/06/04 06:27:47 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.17 2009/06/04 06:47:36 dholland Exp $");
#endif
#endif /* not lint */
@@ -69,7 +69,6 @@ FILE *debugfp; /* file for debug output */
FILE *inputfp; /* file for debug input */
const char pdir[4] = "-\\|/";
-char fmtbuf[128];
struct spotstr board[BAREA]; /* info for board */
struct combostr frames[FAREA]; /* storage for all frames */
@@ -333,14 +332,15 @@ again:
int
readinput(FILE *fp)
{
- char *cp;
int c;
+ char buf[128];
+ size_t pos;
- cp = fmtbuf;
- while ((c = getc(fp)) != EOF && c != '\n')
- *cp++ = c;
- *cp = '\0';
- return (ctos(fmtbuf));
+ pos = 0;
+ while ((c = getc(fp)) != EOF && c != '\n' && pos < sizeof(buf) - 1)
+ buf[pos++] = c;
+ buf[pos] = '\0';
+ return ctos(buf);
}
#ifdef DEBUG