From 5201ca857aeecdabe4e03794af0461e574dddbca Mon Sep 17 00:00:00 2001 From: dholland Date: Thu, 4 Jun 2009 06:47:36 +0000 Subject: Remove global scratch string buffer. Don't zoom off the end while reading user input, either. --- gomoku/gomoku.h | 3 +-- gomoku/main.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'gomoku') 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 -- cgit v1.2.3-56-ge451