Module Name:    src
Committed By:   joerg
Date:           Wed Feb 16 18:35:39 UTC 2011

Modified Files:
        src/usr.bin/grep: fastgrep.c file.c util.c

Log Message:
Fix signed / unsigned issues. Refactor basename usage to use a local
copy and do it only once, not for each pattern. Remove late inline.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/grep/fastgrep.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/grep/file.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/grep/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/grep/fastgrep.c
diff -u src/usr.bin/grep/fastgrep.c:1.1 src/usr.bin/grep/fastgrep.c:1.2
--- src/usr.bin/grep/fastgrep.c:1.1	Wed Feb 16 01:31:33 2011
+++ src/usr.bin/grep/fastgrep.c	Wed Feb 16 18:35:39 2011
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fastgrep.c,v 1.1 2011/02/16 01:31:33 joerg Exp $");
+__RCSID("$NetBSD: fastgrep.c,v 1.2 2011/02/16 18:35:39 joerg Exp $");
 
 #include <limits.h>
 #include <stdbool.h>
@@ -61,8 +61,7 @@
 	fg->eol = false;
 	fg->reversed = false;
 
-	fg->pattern = grep_malloc(strlen(pat) + 1);
-	strcpy(fg->pattern, pat);
+	fg->pattern = (unsigned char *)grep_strdup(pat);
 
 	/* Preprocess pattern. */
 	for (i = 0; i <= UCHAR_MAX; i++)
@@ -120,7 +119,8 @@
 	 * string respectively.
 	 */
 	fg->pattern = grep_malloc(fg->len + 1);
-	strlcpy(fg->pattern, pat + (bol ? 1 : 0) + wflag, fg->len + 1);
+	strlcpy((char *)fg->pattern, pat + (bol ? 1 : 0) + wflag,
+	    fg->len + 1);
 
 	/* Look for ways to cheat...er...avoid the full regex engine. */
 	for (i = 0; i < fg->len; i++) {

Index: src/usr.bin/grep/file.c
diff -u src/usr.bin/grep/file.c:1.4 src/usr.bin/grep/file.c:1.5
--- src/usr.bin/grep/file.c:1.4	Wed Feb 16 01:31:33 2011
+++ src/usr.bin/grep/file.c	Wed Feb 16 18:35:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: file.c,v 1.4 2011/02/16 01:31:33 joerg Exp $	*/
+/*	$NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $	*/
 /*	$FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $	*/
 /*	$OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $	*/
 
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: file.c,v 1.4 2011/02/16 01:31:33 joerg Exp $");
+__RCSID("$NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -139,13 +139,13 @@
 	if (bufrem == 0) {
 		/* Return zero length to indicate EOF */
 		*lenp = 0;
-		return (bufpos);
+		return ((char *)bufpos);
 	}
 
 	/* Look for a newline in the remaining part of the buffer */
 	if ((p = memchr(bufpos, '\n', bufrem)) != NULL) {
 		++p; /* advance over newline */
-		ret = bufpos;
+		ret = (char *)bufpos;
 		len = p - bufpos;
 		bufrem -= len;
 		bufpos = p;
@@ -179,7 +179,7 @@
 		break;
 	}
 	*lenp = len;
-	return (lnbuf);
+	return ((char *)lnbuf);
 
 error:
 	*lenp = 0;

Index: src/usr.bin/grep/util.c
diff -u src/usr.bin/grep/util.c:1.7 src/usr.bin/grep/util.c:1.8
--- src/usr.bin/grep/util.c:1.7	Wed Feb 16 01:31:33 2011
+++ src/usr.bin/grep/util.c	Wed Feb 16 18:35:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.7 2011/02/16 01:31:33 joerg Exp $	*/
+/*	$NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $	*/
 /*	$FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $	*/
 /*	$OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $	*/
 
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: util.c,v 1.7 2011/02/16 01:31:33 joerg Exp $");
+__RCSID("$NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -57,20 +57,23 @@
 bool
 file_matching(const char *fname)
 {
+	char *fname_base, *fname_copy;
 	bool ret;
 
 	ret = finclude ? false : true;
+	fname_copy = grep_strdup(fname);
+	fname_base = basename(fname_copy);
 
 	for (unsigned int i = 0; i < fpatterns; ++i) {
-		if (fnmatch(fpattern[i].pat,
-		    fname, 0) == 0 || fnmatch(fpattern[i].pat,
-		    basename(fname), 0) == 0) {
+		if (fnmatch(fpattern[i].pat, fname, 0) == 0 ||
+		    fnmatch(fpattern[i].pat, fname_base, 0) == 0) {
 			if (fpattern[i].mode == EXCL_PAT)
 				return (false);
 			else
 				ret = true;
 		}
 	}
+	free(fname_copy);
 	return (ret);
 }
 
@@ -279,7 +282,7 @@
  * matches.  The matching lines are passed to printline() to display the
  * appropriate output.
  */
-static inline int
+static int
 procline(struct str *l, int nottext)
 {
 	regmatch_t matches[MAX_LINE_MATCHES];

Reply via email to