From 7488286083399a10a09ab458cd029ad113ba06c3 Mon Sep 17 00:00:00 2001 From: Charles Longeau Date: Thu, 6 Sep 2007 20:50:56 +0000 Subject: use strcspn to properly overwrite '\n' in fgets returned buffer ok moritz@ ray@ --- games/factor/factor.c | 7 +++---- games/primes/primes.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'games') diff --git a/games/factor/factor.c b/games/factor/factor.c index c8b87a62fb3..cb6ede2c892 100644 --- a/games/factor/factor.c +++ b/games/factor/factor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: factor.c,v 1.16 2006/03/12 00:32:50 deraadt Exp $ */ +/* $OpenBSD: factor.c,v 1.17 2007/09/06 20:50:55 chl Exp $ */ /* $NetBSD: factor.c,v 1.5 1995/03/23 08:28:07 cgd Exp $ */ /* @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)factor.c 8.4 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$OpenBSD: factor.c,v 1.16 2006/03/12 00:32:50 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: factor.c,v 1.17 2007/09/06 20:50:55 chl Exp $"; #endif #endif /* not lint */ @@ -118,8 +118,7 @@ main(int argc, char *argv[]) err(1, "stdin"); exit (0); } - if (*(p = buf + strlen(buf) - 1) == '\n') - *p = '\0'; + buf[strcspn(buf, "\n")] = '\0'; for (p = buf; isblank(*p); ++p); if (*p == '\0') continue; diff --git a/games/primes/primes.c b/games/primes/primes.c index 71301aa7796..a42aefb6e22 100644 --- a/games/primes/primes.c +++ b/games/primes/primes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: primes.c,v 1.13 2004/07/09 15:59:26 deraadt Exp $ */ +/* $OpenBSD: primes.c,v 1.14 2007/09/06 20:50:55 chl Exp $ */ /* $NetBSD: primes.c,v 1.5 1995/04/24 12:24:47 cgd Exp $ */ /* @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)primes.c 8.5 (Berkeley) 5/10/95"; #else -static char rcsid[] = "$OpenBSD: primes.c,v 1.13 2004/07/09 15:59:26 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: primes.c,v 1.14 2007/09/06 20:50:55 chl Exp $"; #endif #endif /* not lint */ @@ -196,8 +196,7 @@ read_num_buf(void) err(1, "stdin"); exit(0); } - if (*(p = buf + strlen(buf) - 1) == '\n') - *p = '\0'; + buf[strcspn(buf, "\n")] = '\0'; for (p = buf; isblank(*p); ++p); if (*p == '\0') continue; -- cgit v1.2.3