From 18590f6c720ae49a5bb4d811e6827d85c513fcfe Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 11 Sep 2007 15:21:06 +0000 Subject: use strcspn to properly overwrite '\n' in fgets returned buffer ok pyr@, ray@, millert@, moritz@, chl@ --- games/atc/main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'games/atc/main.c') 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"); -- cgit v1.2.3