PERFORCE change 143998 for review
Gabor Kovesdan
gabor at FreeBSD.org
Mon Jun 23 22:29:18 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=143998
Change 143998 by gabor at gabor_server on 2008/06/23 22:28:22
- Allow values up to ULLONG_MAX for -A/-B/-C/-m
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#37 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.h#19 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#33 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#37 (text+ko) ====
@@ -67,7 +67,8 @@
/* 9*/ "context out of range",
/*10*/ "FreeBSD grep 2.5.1\n",
/*11*/ "Unknown binary-files option",
-/*12*/ "Binary file %s matches\n"
+/*12*/ "Binary file %s matches\n",
+/*12*/ "Value out of range"
};
nl_catd catalog;
@@ -87,8 +88,8 @@
char re_error[RE_ERROR_BUF + 1];
/* Command-line flags */
-int Aflag; /* -A x: print x lines trailing each match */
-int Bflag; /* -B x: print x lines leading each match */
+unsigned long long Aflag; /* -A x: print x lines trailing each match */
+unsigned long long Bflag; /* -B x: print x lines leading each match */
int Dflag; /* -D: do not process device files if optarg is passed */
int Eflag; /* -E: interpret pattern as extended regexp */
int Fflag; /* -F: interpret pattern as list of fixed strings */
@@ -118,7 +119,7 @@
int nullflag; /* --null */
char *label; /* --label */
char *color; /* --color */
-long long mcount; /* count for -m */
+unsigned long long mcount; /* count for -m */
int binbehave = BIN_FILE_BIN;
@@ -361,17 +362,14 @@
{
int c, lastc, prevoptind, newarg, i, needpattern;
struct patfile *patfile, *pf_next;
- long l;
char *ep;
struct stat *finfo = 0;
+ unsigned long long l;
setlocale(LC_ALL, "");
#ifndef WITHOUT_NLS
catalog = catopen("grep", NL_CAT_LOCALE);
- if (catalog == ((nl_catd)-1))
- printf("HIBA: %d\n", errno);
-
#endif
SLIST_INIT(&patfilelh);
@@ -412,20 +410,27 @@
case '5': case '6': case '7': case '8': case '9':
if (newarg || !isdigit(lastc))
Aflag = 0;
- else if (Aflag > INT_MAX / 10)
+ else if (Aflag > LLONG_MAX / 10)
errx(2, getstr(9));
Aflag = Bflag = (Aflag * 10) + (c - '0');
break;
+ case 'C':
+ if (optarg == NULL) {
+ Aflag = Bflag = 2;
+ break;
+ }
+ /* FALLTHROUGH */
case 'A':
case 'B':
- l = strtol(optarg, &ep, 10);
- if (ep == optarg || *ep != '\0' ||
- l <= 0 || l >= INT_MAX)
+ l = strtoull(optarg, &ep, 10);
+ if ((errno == ERANGE) && (l == ULLONG_MAX))
errx(2, getstr(9));
if (c == 'A')
- Aflag = (int)l;
+ Aflag = l;
+ else if (c == 'B')
+ Bflag = l;
else
- Bflag = (int)l;
+ Aflag = Bflag = l;
break;
case 'a':
binbehave = BIN_FILE_TEXT;
@@ -433,17 +438,6 @@
case 'b':
bflag = 1;
break;
- case 'C':
- if (optarg == NULL)
- Aflag = Bflag = 2;
- else {
- l = strtol(optarg, &ep, 10);
- if (ep == optarg || *ep != '\0' ||
- l <= 0 || l >= INT_MAX)
- errx(2, getstr(9));
- Aflag = Bflag = (int)l;
- }
- break;
case 'c':
cflag = 1;
break;
@@ -511,7 +505,9 @@
break;
case 'm':
mflag++;
- mcount = strtoll(optarg, (char **)NULL, 10);
+ mcount = strtoull(optarg, (char **)NULL, 10);
+ if ((errno == ERANGE) && (mcount == ULLONG_MAX))
+ err(2, getstr(13));
break;
case 'n':
nflag = 1;
==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#19 (text+ko) ====
@@ -72,11 +72,11 @@
extern int cflags, eflags;
/* Command line flags */
-extern int Aflag, Bflag, Dflag, Eflag, Fflag, Gflag, Hflag, Jflag,
+extern int Dflag, Eflag, Fflag, Gflag, Hflag, Jflag,
Lflag, Oflag, Pflag, Rflag, Zflag,
bflag, cflag, dflag, hflag, iflag, lflag, mflag, nflag, oflag,
qflag, sflag, vflag, wflag, xflag, nullflag;
-extern long long mcount;
+extern unsigned long long Aflag, Bflag, mcount;
extern char *color, *label;
extern int binbehave;
==== //depot/projects/soc2008/gabor_textproc/grep/util.c#33 (text+ko) ====
More information about the p4-projects
mailing list