summaryrefslogtreecommitdiff
path: root/games/atc/main.c
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:21:06 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2007-09-11 15:21:06 +0000
commit18590f6c720ae49a5bb4d811e6827d85c513fcfe (patch)
treefaa7e813da1b9d96e659b374d353a543d00380bf /games/atc/main.c
parenta737f2f8b1f877858f2553f91964fd9c3ab037fc (diff)
use strcspn to properly overwrite '\n' in fgets returned buffer
ok pyr@, ray@, millert@, moritz@, chl@
Diffstat (limited to 'games/atc/main.c')
-rw-r--r--games/atc/main.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/games/atc/main.c b/games/atc/main.c
index 35d7ae8fb01..ab15b9f3603 100644
--- a/games/atc/main.c
+++ b/games/atc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.17 2007/04/13 13:41:44 sobrado Exp $ */
+/* $OpenBSD: main.c,v 1.18 2007/09/11 15:21:05 gilles Exp $ */
/* $NetBSD: main.c,v 1.4 1995/04/27 21:22:25 mycroft Exp $ */
/*-
@@ -52,7 +52,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.17 2007/04/13 13:41:44 sobrado Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.18 2007/09/11 15:21:05 gilles Exp $";
#endif
#endif /* not lint */
@@ -272,8 +272,8 @@ default_game(void)
return (NULL);
}
fclose(fp);
- if ((p = strchr(line, '\n')) != NULL)
- *p = '\0';
+
+ line[strcspn(line, "\n")] = '\0';
if (strlen(line) + strlen(_PATH_GAMES) >= sizeof(file)) {
warnx("default game name too long");
return (NULL);
@@ -301,8 +301,7 @@ okay_game(const char *s)
while (fgets(line, sizeof(line), fp) != NULL) {
char *p;
- if ((p = strchr(line, '\n')) != NULL)
- *p = '\0';
+ line[strcspn(line, "\n")] = '\0';
if (strcmp(s, line) == 0) {
if (strlen(line) + strlen(_PATH_GAMES) >= sizeof(file)) {
warnx("game name too long");