From 4fd6ed324346681d94337dd681df9264591cbde1 Mon Sep 17 00:00:00 2001 From: gilles Date: Tue, 11 Sep 2007 15:47:17 +0000 Subject: use strcspn to properly overwrite '\n' in fgets returned buffer ok pyr@, ray@, millert@, moritz@, chl@ --- usr.bin/diff/diffreg.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'usr.bin/diff/diffreg.c') diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 4bb8d9e1d74..53209117025 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.69 2007/06/09 05:16:21 ray Exp $ */ +/* $OpenBSD: diffreg.c,v 1.70 2007/09/11 15:47:17 gilles Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -65,7 +65,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.69 2007/06/09 05:16:21 ray Exp $"; +static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.70 2007/09/11 15:47:17 gilles Exp $"; #endif /* not lint */ #include @@ -1300,7 +1300,6 @@ match_function(const long *f, int pos, FILE *file) unsigned char buf[FUNCTION_CONTEXT_SIZE]; size_t nc; int last = lastline; - char *p; char *state = NULL; lastline = pos; @@ -1312,9 +1311,8 @@ match_function(const long *f, int pos, FILE *file) nc = fread(buf, 1, nc, file); if (nc > 0) { buf[nc] = '\0'; - p = strchr(buf, '\n'); - if (p != NULL) - *p = '\0'; + buf[strcspn(buf, "\n")] = '\0'; + if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { if (begins_with(buf, "private:")) { if (!state) -- cgit v1.2.3-59-g8ed1b