PERFORCE change 163331 for review

Gabor Kovesdan gabor at FreeBSD.org
Tue Jun 2 02:41:59 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=163331

Change 163331 by gabor at gabor_server on 2009/06/02 02:41:55

	- Make it WARNS=6 clean

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/Makefile#21 edit
.. //depot/projects/soc2008/gabor_textproc/grep/fastgrep.c#14 edit
.. //depot/projects/soc2008/gabor_textproc/grep/file.c#44 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#88 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.h#50 edit
.. //depot/projects/soc2008/gabor_textproc/grep/queue.c#8 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#83 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/grep/Makefile#21 (text+ko) ====

@@ -15,7 +15,8 @@
 	grep.1 zegrep.1 \
 	grep.1 zfgrep.1
 
-CFLAGS+= -std=c99 -Wall -pedantic
+CFLAGS+=	-std=c99
+WARNS?=	6
 
 LDADD=	-lz -lbz2
 DPADD=	${LIBZ} ${LIBBZ2}

==== //depot/projects/soc2008/gabor_textproc/grep/fastgrep.c#14 (text+ko) ====

@@ -55,7 +55,7 @@
 void
 fgrepcomp(fastgrep_t *fg, const char *pat)
 {
-	int	 i;
+	unsigned int	 i;
 
 	/* Initialize. */
 	fg->len = strlen(pat);
@@ -63,10 +63,11 @@
 	fg->eol = 0;
 	fg->reversed = 0;
 
-	fg->pattern = (unsigned char *)pat;	/* really const */
+	fg->pattern = grep_malloc(strlen(pat) + 1);
+	strcpy(fg->pattern, pat);
 
 	/* Preprocess pattern. */
-	for (i = 0; i <= (signed)UCHAR_MAX; i++)
+	for (i = 0; i <= UCHAR_MAX; i++)
 		fg->qsBc[i] = fg->len;
 	for (i = 1; i < fg->len; i++)
 		fg->qsBc[fg->pattern[i]] = fg->len - i;
@@ -78,7 +79,7 @@
 int
 fastcomp(fastgrep_t *fg, const char *pat)
 {
-	int	 i;
+	unsigned int	 i;
 	int	 bol = 0;
 	int	 eol = 0;
 	int	 shiftPatternLen;
@@ -154,7 +155,7 @@
 	 */
 	if ((!(lflag || cflag)) && ((!(bol || eol)) &&
 	    ((lastHalfDot) && ((firstHalfDot < 0) ||
-	    ((fg->len - (lastHalfDot + 1)) < firstHalfDot)))) && !oflag && !color) {
+	    ((fg->len - (lastHalfDot + 1)) < (size_t)firstHalfDot)))) && !oflag && !color) {
 		fg->reversed = 1;
 		hasDot = fg->len - (firstHalfDot < 0 ?
 		    firstLastHalfDot : firstHalfDot) - 1;
@@ -184,7 +185,7 @@
 	shiftPatternLen = fg->len - hasDot;
 
 	/* Preprocess pattern. */
-	for (i = 0; i <= UCHAR_MAX; i++)
+	for (i = 0; i <= (signed)UCHAR_MAX; i++)
 		fg->qsBc[i] = shiftPatternLen;
 	for (i = hasDot + 1; i < fg->len; i++) {
 		fg->qsBc[fg->pattern[i]] = fg->len - i;
@@ -203,10 +204,10 @@
 int
 grep_search(fastgrep_t *fg, unsigned char *data, size_t len, regmatch_t *pmatch)
 {
-	int	 j;
-	int	 ret = REG_NOMATCH;
+	unsigned int	 j;
+	int		 ret = REG_NOMATCH;
 
-	if (pmatch->rm_so == len)
+	if (pmatch->rm_so == (ssize_t)len)
 		return (ret);
 
 	if (fg->bol && pmatch->rm_so != 0) {
@@ -282,25 +283,25 @@
 static int
 grep_cmp(const unsigned char *pat, const unsigned char *data, size_t len)
 {
-	int	 i;
+	unsigned int	 i;
 	size_t	 size;
 	wchar_t	*wdata, *wpat;
 
 	if (iflag) {
-		if ((size = mbstowcs(NULL, (const char *)data, 0)) == -1)
+		if ((size = mbstowcs(NULL, (const char *)data, 0)) == ((size_t) - 1))
 			return (-1);
 
 		wdata = grep_malloc(size * sizeof(wint_t));
 
-		if (mbstowcs(wdata, (const char *)data, size) == -1)
+		if (mbstowcs(wdata, (const char *)data, size) == ((size_t) - 1))
 			return (-1);
 
-		if ((size = mbstowcs(NULL, (const char *)pat, 0)) == -1)
+		if ((size = mbstowcs(NULL, (const char *)pat, 0)) == ((size_t) - 1))
 			return (-1);
 
 		wpat = grep_malloc(size * sizeof(wint_t));
 
-		if (mbstowcs(wpat, (const char *)pat, size) == -1)
+		if (mbstowcs(wpat, (const char *)pat, size) == ((size_t) - 1))
 			return (-1);
 		for (i = 0; i < len; i++) {
 			if ((towlower(wpat[i]) == towlower(wdata[i])) || ((grepbehave != GREP_FIXED) && wpat[i] == L'.'))

==== //depot/projects/soc2008/gabor_textproc/grep/file.c#44 (text+ko) ====

@@ -122,10 +122,9 @@
 char *
 grep_fgetln(struct file *f, size_t *len)
 {
-	int		 i = 0;
 	int		 ch = 0;
 	struct stat	 st;
-	size_t		 bufsiz;
+	size_t		 bufsiz, i = 0;
 
 	/* Fill in the buffer if it is empty. */
 	if (binbufptr == NULL) {
@@ -203,7 +202,7 @@
  * Opens a normal, a gzipped or a bzip2 compressed file for processing.
  */
 struct file *
-grep_open(char *path)
+grep_open(const char *path)
 {
 	struct file	*f;
 

==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#88 (text+ko) ====

@@ -62,7 +62,7 @@
  * Default messags to use when NLS is disabled or no catalogue
  * is found.
  */
-char	*errstr[] = {
+const char	*errstr[] = {
 	"",
 /* 1*/	"(standard input)",
 /* 2*/	"cannot read bzip2 compressed file",
@@ -84,13 +84,13 @@
 int		 matchall;
 
 /* Searching patterns */
-int		 patterns, pattern_sz;
+unsigned int	 patterns, pattern_sz;
 char		**pattern;
 regex_t		*r_pattern;
 fastgrep_t	*fg_pattern;
 
 /* Filename exclusion/inclusion patterns */
-int		 epatterns, epattern_sz;
+unsigned int	 epatterns, epattern_sz;
 struct epat	*epattern;
 
 /* For regex errors  */
@@ -163,7 +163,7 @@
 	exit(2);
 }
 
-static char	*optstr = "0123456789A:B:C:D:EFGHIJLOPSRUVZabcd:e:f:hilm:nopqrsuvwxy";
+static const char	*optstr = "0123456789A:B:C:D:EFGHIJLOPSRUVZabcd:e:f:hilm:nopqrsuvwxy";
 
 struct option long_options[] =
 {
@@ -285,11 +285,11 @@
 int
 main(int argc, char *argv[])
 {
-	int		 c, lastc, prevoptind, newarg, i, needpattern;
+	int		 c, lastc, prevoptind, newarg, needpattern;
+	unsigned int	 i, eargc, aargc;
 	char		*ep;
 	unsigned long long l;
 	char		**eargv, **aargv, *eopts;
-	int		 eargc, aargc;
 
 	setlocale(LC_ALL, "");
 
@@ -540,12 +540,12 @@
 				errx(2, getstr(11));
 			break;
 		case COLOR_OPT:
-			if (optarg == NULL)
-				optarg = "auto";
-			if (strcmp("auto", optarg) == 0 || strcmp("always", optarg) == 0 ) {
+			if (optarg == NULL || strcmp("auto", optarg) == 0 || strcmp("always", optarg) == 0 ) {
 				color = getenv("GREP_COLOR");
-				if (color == NULL)
-					color = "01;31";
+				if (color == NULL) {
+					color = grep_malloc(sizeof(char) * 6);
+					strcpy(color, "01;31");
+				}
 			} else if (strcmp("never", optarg) == 0)
 				color = NULL;
 			else

==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#50 (text+ko) ====

@@ -43,7 +43,7 @@
 #define getstr(n)	 catgets(catalog, 1, n, errstr[n])
 #endif
 
-extern char		*errstr[];
+extern const char		*errstr[];
 
 #define VERSION		"2.5.1-FreeBSD"
 
@@ -102,7 +102,7 @@
 
 typedef struct {
 	unsigned char	*pattern;
-	int		 len;
+	size_t		 len;
 	int		 qsBc[UCHAR_MAX + 1];
 	/* flags */
 	int		 bol;
@@ -122,7 +122,8 @@
 extern char	*color, *label;
 extern int	 grepbehave, binbehave, filebehave, devbehave, dirbehave, linkbehave;
 
-extern int	 first, prev, matchall, patterns, epatterns, tail, notfound;
+extern int	 first, prev, matchall, tail, notfound;
+extern unsigned int patterns, epatterns;
 extern char    **pattern;
 extern struct epat *epattern;
 extern regex_t	*r_pattern, *er_pattern;
@@ -133,7 +134,7 @@
 extern char	 re_error[RE_ERROR_BUF + 1];	/* Seems big enough */
 
 /* util.c */
-int	 procfile(char *fn);
+int	 procfile(const char *fn);
 int	 grep_tree(char **argv);
 void	*grep_malloc(size_t size);
 void	*grep_calloc(size_t nmemb, size_t size);
@@ -148,7 +149,7 @@
 /* file.c */
 void		 grep_close(struct file *f);
 struct file	*grep_stdin_open(void);
-struct file	*grep_open(char *path);
+struct file	*grep_open(const char *path);
 int		 grep_feof(struct file *f);
 int		 grep_fgetc(struct file *f);
 char		*grep_fgetln(struct file *f, size_t *len);

==== //depot/projects/soc2008/gabor_textproc/grep/queue.c#8 (text+ko) ====

@@ -53,7 +53,7 @@
 };
 
 static STAILQ_HEAD(, qentry)	queue = STAILQ_HEAD_INITIALIZER(queue);
-static int		 	count;
+static unsigned long long	count;
 
 static struct qentry	*dequeue(void);
 

==== //depot/projects/soc2008/gabor_textproc/grep/util.c#83 (text+ko) ====

@@ -65,8 +65,9 @@
 {
 	FTS		*fts;
 	FTSENT		*p;
-	int		 i, c, ok, fts_flags;
+	int		 c, ok, fts_flags;
 	char		*d, *dir;
+	unsigned int	 i;
 
 	c = fts_flags = 0;
 
@@ -142,7 +143,7 @@
  * passing the lines to  procline().
  */
 int
-procfile(char *fn)
+procfile(const char *fn)
 {
 	struct str	 ln;
 	struct file	*f;
@@ -179,7 +180,8 @@
 		return (0);
 	}
 
-	ln.file = fn;
+	ln.file = grep_malloc(strlen(fn) + 1);
+	strcpy(ln.file, fn);
 	ln.line_no = 0;
 	ln.len = 0;
 	linesqueued = 0;
@@ -251,8 +253,9 @@
 {
 	regmatch_t	 pmatch;
 	regmatch_t	 matches[MAX_LINE_MATCHES];
-	regoff_t	 st = 0;
-	int		 c = 0, i, r = 0, m = 0;
+	size_t		 st = 0;
+	int		 c = 0, r = 0, m = 0;
+	unsigned int	 i;
 
 	if (!matchall) {
 		/* Loop to process the whole line */
@@ -280,21 +283,21 @@
 					continue;
 				/* Check for full match */
 				if (r == 0 && xflag)
-					if (pmatch.rm_so != 0 || pmatch.rm_eo != l->len)
+					if (pmatch.rm_so != 0 || (size_t)pmatch.rm_eo != l->len)
 						r = REG_NOMATCH;
 				/* Check for whole word match */
-				if (r == 0 && wflag && pmatch.rm_so != 0 && pmatch.rm_eo != l->len) {
+				if (r == 0 && wflag && pmatch.rm_so != 0 && (size_t)pmatch.rm_eo != l->len) {
 					wchar_t	*wbegin;
 					wint_t	 wend;
 					size_t	 size;
 
 					size = mbstowcs(NULL, l->dat, pmatch.rm_so);
 
-					if (size == -1)
+					if (size == ((size_t) - 1))
 						r = REG_NOMATCH;
 					else {
 						wbegin = grep_malloc(size);
-						if (mbstowcs(wbegin, l->dat, pmatch.rm_so) == -1)
+						if (mbstowcs(wbegin, l->dat, pmatch.rm_so) == ((size_t) - 1))
 							r = REG_NOMATCH;
 						else if (sscanf(&l->dat[pmatch.rm_eo], "%lc", &wend) != 1)
 							r = REG_NOMATCH;
@@ -316,7 +319,7 @@
 			if (!oflag && !color)
 				break;
 
-			if (st == pmatch.rm_so)
+			if (st == (size_t)pmatch.rm_so)
 				break; 	/* No matches */
 		}
 	} else


More information about the p4-projects mailing list