Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/grep Fix signed / unsigned issues. Refactor basename...
details: https://anonhg.NetBSD.org/src/rev/c88ca8bfed21
branches: trunk
changeset: 762139:c88ca8bfed21
user: joerg <joerg%NetBSD.org@localhost>
date: Wed Feb 16 18:35:39 2011 +0000
description:
Fix signed / unsigned issues. Refactor basename usage to use a local
copy and do it only once, not for each pattern. Remove late inline.
diffstat:
usr.bin/grep/fastgrep.c | 8 ++++----
usr.bin/grep/file.c | 10 +++++-----
usr.bin/grep/util.c | 15 +++++++++------
3 files changed, 18 insertions(+), 15 deletions(-)
diffs (129 lines):
diff -r 5a7af0110f39 -r c88ca8bfed21 usr.bin/grep/fastgrep.c
--- a/usr.bin/grep/fastgrep.c Wed Feb 16 17:57:44 2011 +0000
+++ b/usr.bin/grep/fastgrep.c Wed Feb 16 18:35:39 2011 +0000
@@ -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++) {
diff -r 5a7af0110f39 -r c88ca8bfed21 usr.bin/grep/file.c
--- a/usr.bin/grep/file.c Wed Feb 16 17:57:44 2011 +0000
+++ b/usr.bin/grep/file.c Wed Feb 16 18:35:39 2011 +0000
@@ -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;
diff -r 5a7af0110f39 -r c88ca8bfed21 usr.bin/grep/util.c
--- a/usr.bin/grep/util.c Wed Feb 16 17:57:44 2011 +0000
+++ b/usr.bin/grep/util.c Wed Feb 16 18:35:39 2011 +0000
@@ -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];
Home |
Main Index |
Thread Index |
Old Index