? gnu/dist/grep/barbar ? gnu/dist/grep/lib/xstrtoimax.c ? gnu/dist/grep/src/barbar ? gnu/dist/grep/src/dfa.c.done ? gnu/dist/grep/src/dfa.h.done ? gnu/dist/grep/src/foofoo ? gnu/dist/grep/src/patch3-done ? gnu/dist/grep/src/patch3-todo ? gnu/usr.bin/grep/dumpithere ? gnu/usr.bin/grep/makit ? gnu/usr.bin/grep/testithere ? gnu/usr.bin/grep/grep/.gdbinit ? gnu/usr.bin/grep/grep/grep ? gnu/usr.bin/grep/grep/grep.html1 ? gnu/usr.bin/grep/grep/grep.info ? gnu/usr.bin/grep/lib/xstrtoumax.d Index: gnu/dist/grep/lib/Makefile.in =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/lib/Makefile.in,v retrieving revision 1.1.1.2 diff -u -r1.1.1.2 Makefile.in --- gnu/dist/grep/lib/Makefile.in 13 Feb 2003 07:43:14 -0000 1.1.1.2 +++ gnu/dist/grep/lib/Makefile.in 27 Dec 2012 14:00:02 -0000 @@ -108,7 +108,7 @@ libgreputils_a_SOURCES = \ closeout.c error.c exclude.c hard-locale.c \ - isdir.c obstack.c quotearg.c savedir.c xmalloc.c xstrtol.c xstrtoumax.c + isdir.c obstack.c quotearg.c savedir.c xmalloc.c xstrtol.c xstrtoimax.c libgreputils_a_LIBADD = @LIBOBJS@ @ALLOCA@ @@ -129,7 +129,7 @@ am_libgreputils_a_OBJECTS = closeout$U.$(OBJEXT) error$U.$(OBJEXT) \ exclude$U.$(OBJEXT) hard-locale$U.$(OBJEXT) isdir$U.$(OBJEXT) \ obstack$U.$(OBJEXT) quotearg$U.$(OBJEXT) savedir$U.$(OBJEXT) \ - xmalloc$U.$(OBJEXT) xstrtol$U.$(OBJEXT) xstrtoumax$U.$(OBJEXT) + xmalloc$U.$(OBJEXT) xstrtol$U.$(OBJEXT) xstrtiumax$U.$(OBJEXT) libgreputils_a_OBJECTS = $(am_libgreputils_a_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) CPPFLAGS = @CPPFLAGS@ @@ -147,7 +147,7 @@ @AMDEP_TRUE@ $(DEPDIR)/savedir$U.Po $(DEPDIR)/stpcpy.Po \ @AMDEP_TRUE@ $(DEPDIR)/strtoul.Po $(DEPDIR)/strtoull.Po \ @AMDEP_TRUE@ $(DEPDIR)/strtoumax.Po $(DEPDIR)/xmalloc$U.Po \ -@AMDEP_TRUE@ $(DEPDIR)/xstrtol$U.Po $(DEPDIR)/xstrtoumax$U.Po +@AMDEP_TRUE@ $(DEPDIR)/xstrtol$U.Po $(DEPDIR)/xstrtoimax$U.Po COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) @@ -224,7 +224,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strtoumax.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/xmalloc$U.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/xstrtol$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/xstrtoumax$U.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/xstrtoimax$U.Po@am__quote@ distclean-depend: -rm -rf $(DEPDIR) @@ -287,8 +287,8 @@ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xmalloc.c; then echo $(srcdir)/xmalloc.c; else echo xmalloc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xmalloc_.c || rm -f xmalloc_.c xstrtol_.c: xstrtol.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xstrtol.c; then echo $(srcdir)/xstrtol.c; else echo xstrtol.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xstrtol_.c || rm -f xstrtol_.c -xstrtoumax_.c: xstrtoumax.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xstrtoumax.c; then echo $(srcdir)/xstrtoumax.c; else echo xstrtoumax.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xstrtoumax_.c || rm -f xstrtoumax_.c +xstrtoimax_.c: xstrtoimax.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xstrtoimax.c; then echo $(srcdir)/xstrtoimax.c; else echo xstrtoimax.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xstrtoimax_.c || rm -f xstrtoimax_.c alloca_.$(OBJEXT) atexit_.$(OBJEXT) closeout_.$(OBJEXT) \ error_.$(OBJEXT) exclude_.$(OBJEXT) fnmatch_.$(OBJEXT) \ getopt_.$(OBJEXT) getopt1_.$(OBJEXT) hard-locale_.$(OBJEXT) \ @@ -296,7 +296,7 @@ quotearg_.$(OBJEXT) realloc_.$(OBJEXT) regex_.$(OBJEXT) \ savedir_.$(OBJEXT) stpcpy_.$(OBJEXT) strtoul_.$(OBJEXT) \ strtoull_.$(OBJEXT) strtoumax_.$(OBJEXT) xmalloc_.$(OBJEXT) \ -xstrtol_.$(OBJEXT) xstrtoumax_.$(OBJEXT) : $(ANSI2KNR) +xstrtol_.$(OBJEXT) xstrtoimax_.$(OBJEXT) : $(ANSI2KNR) uninstall-info-am: # This directory's subdirectories are mostly independent; you can cd Index: gnu/dist/grep/lib/xstrtol.h =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/lib/xstrtol.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 xstrtol.h --- gnu/dist/grep/lib/xstrtol.h 26 Jan 2003 23:15:13 -0000 1.1.1.1 +++ gnu/dist/grep/lib/xstrtol.h 27 Dec 2012 14:00:02 -0000 @@ -29,7 +29,7 @@ type *val, const char *valid_suffixes)); _DECLARE_XSTRTOL (xstrtol, long int) _DECLARE_XSTRTOL (xstrtoul, unsigned long int) -_DECLARE_XSTRTOL (xstrtoumax, uintmax_t) +_DECLARE_XSTRTOL (xstrtoimax, intmax_t) # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \ do \ Index: gnu/dist/grep/src/dfa.c =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/src/dfa.c,v retrieving revision 1.2 diff -u -r1.2 dfa.c --- gnu/dist/grep/src/dfa.c 26 Jan 2003 23:55:52 -0000 1.2 +++ gnu/dist/grep/src/dfa.c 27 Dec 2012 14:00:04 -0000 @@ -27,6 +27,7 @@ #include #include #include +#include #include #ifdef STDC_HEADERS @@ -36,6 +37,7 @@ extern void free(); #endif + #if defined(HAVE_STRING_H) || defined(STDC_HEADERS) #include #else @@ -185,7 +187,10 @@ if (t < 0) fprintf(stderr, "END"); else if (t < NOTCHAR) - fprintf(stderr, "%c", t); + { + int ch = t; + fprintf(stderr, "%c", ch); + } else { switch (t) @@ -269,10 +274,10 @@ static struct dfa *dfa; /* Find the index of charclass s in dfa->charclasses, or allocate a new charclass. */ -static int +static size_t charclass_index (charclass s) { - int i; + size_t i; for (i = 0; i < dfa->cindex; ++i) if (equal(s, dfa->charclasses[i])) @@ -323,11 +328,11 @@ static char const *lexstart; /* Pointer to beginning of input string. */ static char const *lexptr; /* Pointer to next input character. */ -static int lexleft; /* Number of characters remaining. */ +static size_t lexleft; /* Number of characters remaining. */ static token lasttok; /* Previous token returned; initially END. */ static int laststart; /* True if we're separated from beginning or (, | only by zero-width characters. */ -static int parens; /* Count of outstanding left parens. */ +static size_t parens; /* Count of outstanding left parens. */ static int minrep, maxrep; /* Repeat counts for {m,n}. */ static int hard_LC_COLLATE; /* Nonzero if LC_COLLATE is hard. */ @@ -465,7 +470,7 @@ /* Work area to build a mb_char_classes. */ struct mb_char_classes *work_mbc; - int chars_al, range_sts_al, range_ends_al, ch_classes_al, + size_t chars_al, range_sts_al, range_ends_al, ch_classes_al, equivs_al, coll_elems_al; REALLOC_IF_NECESSARY(dfa->mbcsets, struct mb_char_classes, @@ -857,14 +862,32 @@ char const *p = lexptr; char const *lim = p + lexleft; for (; p != lim && ISASCIIDIGIT (*p); p++) - lo = (lo < 0 ? 0 : lo * 10) + *p - '0'; + { + if (lo < 0) + lo = *p - '0'; + else + { + lo = lo * 10 + *p - '0'; + if (RE_DUP_MAX < lo) + goto normal_char; + } + } if (p != lim && *p == ',') while (++p != lim && ISASCIIDIGIT (*p)) - hi = (hi < 0 ? 0 : hi * 10) + *p - '0'; + { + if (hi < 0) + hi = *p - '0'; + else + { + hi = hi * 10 + *p - '0'; + if (RE_DUP_MAX < hi) + goto normal_char; + } + } else hi = lo; if (p == lim || *p != '}' - || lo < 0 || RE_DUP_MAX < hi || (0 <= hi && hi < lo)) + || lo < 0 || (0 <= hi && hi < lo)) goto normal_char; } @@ -1107,7 +1130,7 @@ /* Recursive descent parser for regular expressions. */ static token tok; /* Lookahead token. */ -static int depth; /* Current depth of a hypothetical stack +static size_t depth; /* Current depth of a hypothetical stack holding deferred productions. This is used to determine the depth that will be required of the real stack later on in @@ -1260,10 +1283,10 @@ } /* Return the number of tokens in the given subexpression. */ -static int +static size_t nsubtoks (int tindex) { - int ntoks1; + size_t ntoks1; switch (dfa->tokens[tindex - 1]) { @@ -1283,9 +1306,9 @@ /* Copy the given subexpression to the top of the tree. */ static void -copytoks (int tindex, int ntokens) +copytoks (size_t tindex, size_t ntokens) { - int i; + size_t i; for (i = 0; i < ntokens; ++i) addtok(dfa->tokens[tindex + i]); @@ -1294,7 +1317,8 @@ static void closure (void) { - int tindex, ntokens, i; + int i; + size_t tindex, ntokens; atom(); while (tok == QMARK || tok == STAR || tok == PLUS || tok == REPMN) @@ -1416,7 +1440,7 @@ static void insert (position p, position_set *s) { - int i; + size_t i; position t1, t2; for (i = 0; i < s->nelem && p.index < s->elems[i].index; ++i) @@ -1441,7 +1465,7 @@ static void merge (position_set const *s1, position_set const *s2, position_set *m) { - int i = 0, j = 0; + size_t i = 0, j = 0; m->nelem = 0; while (i < s1->nelem && j < s2->nelem) @@ -1464,7 +1488,7 @@ static void delete (position p, position_set *s) { - int i; + size_t i; for (i = 0; i < s->nelem; ++i) if (p.index == s->elems[i].index) @@ -1478,12 +1502,12 @@ the given preceding context, or create a new state if there is no such state. Newline and letter tell whether we got here on a newline or letter, respectively. */ -static int +static state_num state_index (struct dfa *d, position_set const *s, int newline, int letter) { - int hash = 0; + size_t hash = 0; int constraint; - int i, j; + state_num i, j; newline = newline ? 1 : 0; letter = letter ? 1 : 0; @@ -1551,7 +1575,7 @@ static void epsclosure (position_set *s, struct dfa const *d) { - int i, j; + size_t i, j; int *visited; position p, old; @@ -1667,26 +1691,26 @@ void dfaanalyze (struct dfa *d, int searchflag) { - int *nullable; /* Nullable stack. */ - int *nfirstpos; /* Element count stack for firstpos sets. */ + size_t *nullable; /* Nullable stack. */ + size_t *nfirstpos; /* Element count stack for firstpos sets. */ position *firstpos; /* Array where firstpos elements are stored. */ - int *nlastpos; /* Element count stack for lastpos sets. */ + size_t *nlastpos; /* Element count stack for lastpos sets. */ position *lastpos; /* Array where lastpos elements are stored. */ int *nalloc; /* Sizes of arrays allocated to follow sets. */ position_set tmp; /* Temporary set for merging sets. */ position_set merged; /* Result of merging sets. */ int wants_newline; /* True if some position wants newline info. */ - int *o_nullable; - int *o_nfirst, *o_nlast; + size_t *o_nullable; + size_t *o_nfirst, *o_nlast; position *o_firstpos, *o_lastpos; - int i, j; + size_t i, j; position *pos; #ifdef DEBUG fprintf(stderr, "dfaanalyze:\n"); for (i = 0; i < d->tindex; ++i) { - fprintf(stderr, " %d:", i); + fprintf(stderr, " %zd:", i); prtok(d->tokens[i]); } putc('\n', stderr); @@ -1694,13 +1718,13 @@ d->searchflag = searchflag; - MALLOC(nullable, int, d->depth); + MALLOC(nullable, size_t, d->depth); o_nullable = nullable; - MALLOC(nfirstpos, int, d->depth); + MALLOC(nfirstpos, size_t, d->depth); o_nfirst = nfirstpos; MALLOC(firstpos, position, d->nleaves); o_firstpos = firstpos, firstpos += d->nleaves; - MALLOC(nlastpos, int, d->depth); + MALLOC(nlastpos, size_t, d->depth); o_nlast = nlastpos; MALLOC(lastpos, position, d->nleaves); o_lastpos = lastpos, lastpos += d->nleaves; @@ -1775,7 +1799,7 @@ else { pos = lastpos + nlastpos[-2]; - for (j = nlastpos[-1] - 1; j >= 0; --j) + for (j = nlastpos[-1]; j-- > 0; ) pos[j] = lastpos[j]; lastpos += nlastpos[-2]; nlastpos[-2] = nlastpos[-1]; @@ -1823,20 +1847,20 @@ } #ifdef DEBUG /* ... balance the above nonsyntactic #ifdef goo... */ - fprintf(stderr, "node %d:", i); + fprintf(stderr, "node %zd:", i); prtok(d->tokens[i]); putc('\n', stderr); fprintf(stderr, nullable[-1] ? " nullable: yes\n" : " nullable: no\n"); fprintf(stderr, " firstpos:"); - for (j = nfirstpos[-1] - 1; j >= 0; --j) + for (j = nfirstpos[-1]; j-- > 0; ) { - fprintf(stderr, " %d:", firstpos[j].index); + fprintf(stderr, " %zd:", firstpos[j].index); prtok(d->tokens[firstpos[j].index]); } fprintf(stderr, "\n lastpos:"); - for (j = nlastpos[-1] - 1; j >= 0; --j) + for (j = nlastpos[-1]; j-- > 0; ) { - fprintf(stderr, " %d:", lastpos[j].index); + fprintf(stderr, " %zd:", lastpos[j].index); prtok(d->tokens[lastpos[j].index]); } putc('\n', stderr); @@ -1854,12 +1878,12 @@ || d->tokens[i] >= CSET) { #ifdef DEBUG - fprintf(stderr, "follows(%d:", i); + fprintf(stderr, "follows(%zd:", i); prtok(d->tokens[i]); fprintf(stderr, "):"); - for (j = d->follows[i].nelem - 1; j >= 0; --j) + for (j = d->follows[i].nelem; j-- > 0;) { - fprintf(stderr, " %d:", d->follows[i].elems[j].index); + fprintf(stderr, " %zd:", d->follows[i].elems[j].index); prtok(d->tokens[d->follows[i].elems[j].index]); } putc('\n', stderr); @@ -1930,11 +1954,11 @@ create a new group labeled with the characters of C and insert this position in that group. */ void -dfastate (int s, struct dfa *d, int trans[]) +dfastate (state_num s, struct dfa *d, state_num trans[]) { position_set grps[NOTCHAR]; /* As many as will ever be needed. */ charclass labels[NOTCHAR]; /* Labels corresponding to the groups. */ - int ngrps = 0; /* Number of groups actually used. */ + size_t ngrps = 0; /* Number of groups actually used. */ position pos; /* Current position being considered. */ charclass matches; /* Set of matching characters. */ int matchesf; /* True if matches is nonempty. */ @@ -1946,16 +1970,16 @@ static charclass newline; /* Set of characters that aren't newline. */ position_set follows; /* Union of the follows of some group. */ position_set tmp; /* Temporary space for merging sets. */ - int state; /* New state. */ + size_t state; /* New state. */ int wants_newline; /* New state wants to know newline context. */ - int state_newline; /* New state on a newline transition. */ + size_t state_newline; /* New state on a newline transition. */ int wants_letter; /* New state wants to know letter context. */ - int state_letter; /* New state on a letter transition. */ + size_t state_letter; /* New state on a letter transition. */ static int initialized; /* Flag for static initialization. */ #ifdef MBS_SUPPORT int next_isnt_1st_byte = 0; /* Flag If we can't add state0. */ #endif - int i, j, k; + size_t i, j, k; /* Initialize the set of letters, if necessary. */ if (! initialized) @@ -2229,10 +2253,10 @@ TODO: Improve this comment, get rid of the unnecessary redundancy. */ static void -build_state (int s, struct dfa *d) +build_state (state_num s, struct dfa *d) { - int *trans; /* The new transition table. */ - int i; + state_num *trans; /* The new transition table. */ + state_num i; /* Set an upper limit on the number of transition tables that will ever exist at once. 1024 is arbitrary. The idea is that the frequently @@ -2268,7 +2292,7 @@ s, *d)) d->success[s] |= 1; - MALLOC(trans, int, NOTCHAR); + MALLOC(trans, state_num, NOTCHAR); dfastate(s, d, trans); /* Now go through the new transition table, and make sure that the trans @@ -2277,13 +2301,13 @@ for (i = 0; i < NOTCHAR; ++i) if (trans[i] >= d->tralloc) { - int oldalloc = d->tralloc; + state_num oldalloc = d->tralloc; while (trans[i] >= d->tralloc) d->tralloc *= 2; - REALLOC(d->realtrans, int *, d->tralloc + 1); + REALLOC(d->realtrans, state_num *, d->tralloc + 1); d->trans = d->realtrans + 1; - REALLOC(d->fails, int *, d->tralloc); + REALLOC(d->fails, state_num *, d->tralloc); REALLOC(d->success, int, d->tralloc); while (oldalloc < d->tralloc) { @@ -2306,9 +2330,9 @@ { d->tralloc = 1; d->trcount = 0; - CALLOC(d->realtrans, int *, d->tralloc + 1); + CALLOC(d->realtrans, state_num *, d->tralloc + 1); d->trans = d->realtrans + 1; - CALLOC(d->fails, int *, d->tralloc); + CALLOC(d->fails, state_num *, d->tralloc); MALLOC(d->success, int, d->tralloc); build_state(0, d); } @@ -2339,13 +2363,13 @@ } static void -realloc_trans_if_necessary(struct dfa *d, int new_state) +realloc_trans_if_necessary(struct dfa *d, state_num new_state) { /* Make sure that the trans and fail arrays are allocated large enough to hold a pointer for the new state. */ if (new_state >= d->tralloc) { - int oldalloc = d->tralloc; + state_num oldalloc = d->tralloc; while (new_state >= d->tralloc) d->tralloc *= 2; @@ -2375,11 +2399,11 @@ But state transition is done just once, otherwise matching succeed or reach the end of the buffer. */ static status_transit_state -transit_state_singlebyte (struct dfa *d, int s, unsigned char const *p, - int *next_state) +transit_state_singlebyte (struct dfa *d, state_num s, unsigned char const *p, + state_num *next_state) { - int *t; - int works = s; + state_num *t; + state_num works = s; status_transit_state rval = TRANSIT_STATE_IN_PROGRESS; @@ -2419,7 +2443,7 @@ `pos' is the position of the period. `index' is the index from the buf_begin, and it is the current position in the buffer. */ static int -match_anychar (struct dfa *d, int s, position pos, int index) +match_anychar (struct dfa *d, state_num s, position pos, size_t index) { int newline = 0; int letter = 0; @@ -2459,9 +2483,9 @@ `pos' is the position of the bracket expression. `index' is the index from the buf_begin, and it is the current position in the buffer. */ int -match_mb_charset (struct dfa *d, int s, position pos, int index) +match_mb_charset (struct dfa *d, state_num s, position pos, size_t index) { - int i; + size_t i; /* used with ->nchars below */ int match; /* Flag which represent that matching succeed. */ int match_len; /* Length of the character (or collating element) with which this operator match. */ @@ -2574,9 +2598,9 @@ in the buffer. Caller MUST free the array which this function return. */ static int* -check_matching_with_multibyte_ops (struct dfa *d, int s, int index) +check_matching_with_multibyte_ops (struct dfa *d, state_num s, size_t index) { - int i; + size_t i; int* rarray; MALLOC(rarray, int, d->states[s].mbps.nelem); @@ -2605,11 +2629,13 @@ `mbclen' and `pps' are the output. `mbclen' is the length of the character consumed, and `pps' is the set this function enumerate. */ static status_transit_state -transit_state_consume_1char (struct dfa *d, int s, unsigned char const **pp, +transit_state_consume_1char (struct dfa *d, state_num s, + unsigned char const **pp, int *match_lens, int *mbclen, position_set *pps) { - int i, j; - int s1, s2; + size_t i, j; + int k; + state_num s1, s2; int* work_mbls; status_transit_state rs = TRANSIT_STATE_DONE; @@ -2621,7 +2647,7 @@ /* Calculate the state which can be reached from the state `s' by consuming `*mbclen' single bytes from the buffer. */ s1 = s; - for (i = 0; i < *mbclen; i++) + for (k = 0; k < *mbclen; k++) { s2 = s1; rs = transit_state_singlebyte(d, s2, (*pp)++, &s1); @@ -2654,15 +2680,15 @@ /* Transit state from s, then return new state and update the pointer of the buffer. This function is for some operator which can match with a multi- byte character or a collating element(which may be multi characters). */ -static int -transit_state (struct dfa *d, int s, unsigned char const **pp) +static state_num +transit_state (struct dfa *d, state_num s, unsigned char const **pp) { - int s1; + state_num s1; int mbclen; /* The length of current input multibyte character. */ int maxlen = 0; - int i, j; + size_t i, j; int *match_lens = NULL; - int nelem = d->states[s].mbps.nelem; /* Just a alias. */ + size_t nelem = d->states[s].mbps.nelem; /* Just a alias. */ position_set follows; unsigned char const *p1 = *pp; status_transit_state rs; @@ -2751,10 +2777,10 @@ size_t dfaexec (struct dfa *d, char const *begin, size_t size, int *backref) { - register int s; /* Current state. */ + register state_num s; /* Current state. */ register unsigned char const *p; /* Current input character. */ register unsigned char const *end; /* One past the last input character. */ - register int **trans, *t; /* Copy of d->trans so it can be optimized + register state_num **trans, *t; /* Copy of d->trans so it can be optimized into a register. */ register unsigned char eol = eolbyte; /* Likewise for eolbyte. */ static int sbit[NOTCHAR]; /* Table for anding with d->success. */ @@ -2781,7 +2807,7 @@ #ifdef MBS_SUPPORT if (MB_CUR_MAX > 1) { - int remain_bytes, i; + ptrdiff_t remain_bytes, i; buf_begin = begin; buf_end = end; @@ -2987,7 +3013,7 @@ void dfafree (struct dfa *d) { - int i; + size_t i; struct dfamust *dm, *ndm; free((ptr_t) d->charclasses); @@ -3181,7 +3207,7 @@ static void freelist (char **cpp) { - int i; + size_t i; if (cpp == NULL) return; @@ -3195,7 +3221,7 @@ static char ** enlist (char **cpp, char *new, size_t len) { - int i, j; + size_t i, j; if (cpp == NULL) return NULL; @@ -3274,7 +3300,7 @@ static char ** addlists (char **old, char **new) { - int i; + size_t i; if (old == NULL || new == NULL) return NULL; @@ -3294,7 +3320,7 @@ { char **both; char **temp; - int lnum, rnum; + size_t lnum, rnum; if (left == NULL || right == NULL) return NULL; @@ -3343,8 +3369,8 @@ must *musts; must *mp; char *result; - int ri; - int i; + size_t ri; + size_t i; int exact; token t; static must must0; @@ -3375,7 +3401,7 @@ fprintf(stderr, "dfamust:\n"); for (i = 0; i < dfa->tindex; ++i) { - fprintf(stderr, " %d:", i); + fprintf(stderr, " %zd:", i); prtok(dfa->tokens[i]); } putc('\n', stderr); @@ -3412,7 +3438,7 @@ char **new; must *lmp; must *rmp; - int j, ln, rn, n; + size_t j, ln, rn, n; rmp = --mp; lmp = --mp; @@ -3550,7 +3576,7 @@ break; } #ifdef DEBUG - fprintf(stderr, " node: %d:", ri); + fprintf(stderr, " node: %zd:", ri); prtok(dfa->tokens[ri]); fprintf(stderr, "\n in:"); for (i = 0; mp->in[i]; ++i) Index: gnu/dist/grep/src/dfa.h =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/src/dfa.h,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 dfa.h --- gnu/dist/grep/src/dfa.h 26 Jan 2003 23:15:29 -0000 1.1.1.3 +++ gnu/dist/grep/src/dfa.h 27 Dec 2012 14:00:05 -0000 @@ -64,11 +64,19 @@ /* Sets of unsigned characters are stored as bit vectors in arrays of ints. */ typedef int charclass[CHARCLASS_INTS]; + +/* States are indexed by state_num values. These are normally + nonnegative but -1 is used as a special value. */ +typedef ptrdiff_t state_num; + /* The regexp is parsed into an array of tokens in postfix form. Some tokens are operators and others are terminal symbols. Most (but not all) of these codes are returned by the lexical analyzer. */ -typedef enum +typedef ptrdiff_t token; + +/* predefined token values */ +enum { END = -1, /* END is a terminal symbol that matches the end of input; any value of END or less in @@ -162,7 +170,7 @@ CSET /* CSET and (and any value greater) is a terminal symbol that matches any of a class of characters. */ -} token; +}; /* Sets are stored in an array in the compiled dfa; the index of the array corresponding to a given set token is given by SET_INDEX(t). */ @@ -223,7 +231,7 @@ a constraint. */ typedef struct { - unsigned index; /* Index into the parse array. */ + size_t index; /* Index into the parse array. */ unsigned constraint; /* Constraint for matching this position. */ } position; @@ -239,13 +247,13 @@ contains an END token. */ typedef struct { - int hash; /* Hash of the positions of this state. */ + size_t hash; /* Hash of the positions of this state. */ position_set elems; /* Positions this state could match. */ char newline; /* True if previous state matched newline. */ char letter; /* True if previous state matched a letter. */ char backref; /* True if this state matches a \. */ unsigned char constraint; /* Constraint for this state to accept. */ - int first_end; /* Token value of the first END in elems. */ + token first_end; /* Token value of the first END in elems. */ #ifdef MBS_SUPPORT position_set mbps; /* Positions which can match multibyte characters. e.g. period. @@ -270,16 +278,16 @@ { int invert; wchar_t *chars; /* Normal characters. */ - int nchars; + size_t nchars; wctype_t *ch_classes; /* Character classes. */ - int nch_classes; + size_t nch_classes; wchar_t *range_sts; /* Range characters (start of the range). */ wchar_t *range_ends; /* Range characters (end of the range). */ - int nranges; + size_t nranges; char **equivs; /* Equivalent classes. */ - int nequivs; + size_t nequivs; char **coll_elems; - int ncoll_elems; /* Collating elements. */ + size_t ncoll_elems; /* Collating elements. */ }; #endif @@ -288,22 +296,22 @@ { /* Stuff built by the scanner. */ charclass *charclasses; /* Array of character sets for CSET tokens. */ - int cindex; /* Index for adding new charclasses. */ - int calloc; /* Number of charclasses currently allocated. */ + size_t cindex; /* Index for adding new charclasses. */ + size_t calloc; /* Number of charclasses currently allocated. */ /* Stuff built by the parser. */ token *tokens; /* Postfix parse array. */ - int tindex; /* Index for adding new tokens. */ - int talloc; /* Number of tokens currently allocated. */ - int depth; /* Depth required of an evaluation stack + size_t tindex; /* Index for adding new tokens. */ + size_t talloc; /* Number of tokens currently allocated. */ + size_t depth; /* Depth required of an evaluation stack used for depth-first traversal of the parse tree. */ - int nleaves; /* Number of leaves on the parse tree. */ - int nregexps; /* Count of parallel regexps being built + size_t nleaves; /* Number of leaves on the parse tree. */ + size_t nregexps; /* Count of parallel regexps being built with dfaparse(). */ #ifdef MBS_SUPPORT /* These stuff are used only if MB_CUR_MAX > 1 or multibyte environments. */ - int nmultibyte_prop; + size_t nmultibyte_prop; int *multibyte_prop; /* The value of multibyte_prop[i] is defined by following rule. if tokens[i] < NOTCHAR @@ -324,14 +332,14 @@ /* Array of the bracket expressoin in the DFA. */ struct mb_char_classes *mbcsets; - int nmbcsets; - int mbcsets_alloc; + size_t nmbcsets; + size_t mbcsets_alloc; #endif /* Stuff owned by the state builder. */ dfa_state *states; /* States of the dfa. */ - int sindex; /* Index for adding new states. */ - int salloc; /* Number of states currently allocated. */ + state_num sindex; /* Index for adding new states. */ + state_num salloc; /* Number of states currently allocated. */ /* Stuff built by the structure analyzer. */ position_set *follows; /* Array of follow sets, indexed by position @@ -350,18 +358,18 @@ beginning of the buffer. */ /* Stuff owned by the executor. */ - int tralloc; /* Number of transition tables that have + state_num tralloc; /* Number of transition tables that have slots so far. */ int trcount; /* Number of transition tables that have actually been built. */ - int **trans; /* Transition tables for states that can + state_num **trans; /* Transition tables for states that can never accept. If the transitions for a state have not yet been computed, or the state could possibly accept, its entry in this table is NULL. */ - int **realtrans; /* Trans always points to realtrans + 1; this + state_num **realtrans; /* Trans always points to realtrans + 1; this is so trans[-1] can contain NULL. */ - int **fails; /* Transition tables after failing to accept + state_num **fails; /* Transition tables after failing to accept on a state that potentially could do so. */ int *success; /* Table of acceptance conditions used in dfaexec and computed in build_state. */ @@ -424,7 +432,7 @@ /* Compute, for each possible character, the transitions out of a given state, storing them in an array of integers. */ -extern void dfastate PARAMS ((int, struct dfa *, int [])); +extern void dfastate PARAMS ((state_num, struct dfa *, state_num [])); /* Error handling. */ Index: gnu/dist/grep/src/grep.c =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/src/grep.c,v retrieving revision 1.13 diff -u -r1.13 grep.c --- gnu/dist/grep/src/grep.c 28 Sep 2010 00:54:04 -0000 1.13 +++ gnu/dist/grep/src/grep.c 27 Dec 2012 14:00:08 -0000 @@ -32,6 +32,7 @@ # include # include #endif +#include #include #include "system.h" #include "getopt.h" @@ -193,17 +194,21 @@ errseen = 1; } -/* Convert STR to a positive integer, storing the result in *OUT. +/* Convert STR to a nonnegative integer, storing the result in *OUT. STR must be a valid context length argument; report an error if it - isn't. */ + isn't. Silently ceiling *OUT at the maximum value, as that is + practically equivalent to infinity for grep's purposes. */ static void -context_length_arg (char const *str, int *out) +context_length_arg (char const *str, intmax_t *out) { - uintmax_t value; - if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK - && 0 <= (*out = value) - && *out == value)) - { + switch (xstrtoimax (str, 0, 10, out, "")) + { + case LONGINT_OK: + case LONGINT_OVERFLOW: + if (0 <= *out) + break; + /* Fall through. */ + default: error (2, 0, "%s: %s", str, _("invalid context length argument")); } } @@ -442,12 +447,12 @@ static int out_file; /* Print filenames. */ static int out_line; /* Print line numbers. */ static int out_byte; /* Print byte offsets. */ -static int out_before; /* Lines of leading context. */ -static int out_after; /* Lines of trailing context. */ +static intmax_t out_before; /* Lines of leading context. */ +static intmax_t out_after; /* Lines of trailing context. */ static int count_matches; /* Count matching lines. */ static int list_files; /* List matching files. */ static int no_filenames; /* Suppress file names. */ -static off_t max_count; /* Stop after outputting this many +static intmax_t max_count; /* Stop after outputting this many lines from an input file. */ static int line_buffered; /* If nonzero, use line buffering, i.e. fflush everyline out. */ @@ -461,8 +466,8 @@ NULL if no character has been output or if it's conceptually before bufbeg. */ static uintmax_t totalnl; /* Total newline count before lastnl. */ -static off_t outleft; /* Maximum number of lines to be output. */ -static int pending; /* Pending lines of output. +static intmax_t outleft; /* Maximum number of lines to be output. */ +static intmax_t pending; /* Pending lines of output. Always kept 0 if out_quiet is true. */ static int done_on_match; /* Stop scanning file on first match. */ static int exit_on_match; /* Exit on first match. */ @@ -639,12 +644,12 @@ /* Print the lines between BEG and LIM. Deal with context crap. If NLINESP is non-null, store a count of lines between BEG and LIM. */ static void -prtext (char const *beg, char const *lim, int *nlinesp) +prtext (char const *beg, char const *lim, intmax_t *nlinesp) { static int used; /* avoid printing "--" before any output */ char const *bp, *p; char eol = eolbyte; - int i, n; + intmax_t i, n; if (!out_quiet && pending > 0) prpending (beg); @@ -703,10 +708,10 @@ /* Scan the specified portion of the buffer, matching lines (or between matching lines if OUT_INVERT is true). Return a count of lines printed. */ -static int +static intmax_t grepbuf (char const *beg, char const *lim) { - int nlines, n; + intmax_t nlines, n; register char const *p; size_t match_offset; size_t match_size; @@ -722,7 +727,7 @@ break; if (!out_invert) { - prtext (b, endp, (int *) 0); + prtext (b, endp, NULL); nlines++; outleft--; if (!outleft || done_on_match) @@ -755,10 +760,10 @@ /* Search a given file. Normally, return a count of lines printed; but if the file is a directory and we search it recursively, then return -2 if there was a match, and -1 otherwise. */ -static int +static intmax_t grep (int fd, char const *file, struct stats *stats) { - int nlines, i; + intmax_t nlines, i; int not_text; size_t residue, save; char oldc; @@ -890,7 +895,7 @@ grepfile (char const *file, struct stats *stats) { int desc; - int count; + intmax_t count; int status; if (! file) @@ -959,7 +964,7 @@ { if (out_file) printf ("%s%c", filename, ':' & filename_mask); - printf ("%d\n", count); + printf ("%" PRIdMAX "\n", count); } status = !count; @@ -1193,12 +1198,12 @@ etc. to the option copies. Return the number N of options found. Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0] etc. Backslash can be used to escape whitespace (and backslashes). */ -static int +static size_t prepend_args (char const *options, char *buf, char **argv) { char const *o = options; char *b = buf; - int n = 0; + size_t n = 0; for (;;) { @@ -1219,6 +1224,8 @@ } } +#define MIN(a,b) (((a)<(b))?(a):(b)) + /* Prepend the whitespace-separated options in OPTIONS to the argument vector of a main program with argument count *PARGC and argument vector *PARGV. */ @@ -1228,10 +1235,14 @@ if (options) { char *buf = xmalloc (strlen (options) + 1); - int prepended = prepend_args (options, buf, (char **) NULL); + size_t prepended = prepend_args (options, buf, (char **) NULL); int argc = *pargc; char * const *argv = *pargv; - char **pp = (char **) xmalloc ((prepended + argc + 1) * sizeof *pp); + char **pp; + enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) }; + if (MAX_ARGS - argc < prepended) + xalloc_die (); + pp = (char **) xmalloc ((prepended + argc + 1) * sizeof *pp); *pargc = prepended + argc; *pargv = pp; *pp++ = *argv++; @@ -1246,10 +1257,10 @@ Process any digit options that were encountered on the way, and store the resulting integer into *DEFAULT_CONTEXT. */ static int -get_nondigit_option (int argc, char *const *argv, int *default_context) +get_nondigit_option (int argc, char *const *argv, intmax_t *default_context) { int opt; - char buf[sizeof (uintmax_t) * CHAR_BIT + 4]; + char buf[sizeof (intmax_t) * CHAR_BIT + 4]; /* XXX -is. */ char *p = buf; /* Set buf[0] to anything but '0', for the leading-zero test below. */ @@ -1288,8 +1299,9 @@ char *keys; size_t keycc, oldcc, keyalloc; int with_filenames; - int opt, cc, status; - int default_context; + size_t cc; + int opt, status; + intmax_t default_context; FILE *fp; extern char *optarg; extern int optind; @@ -1338,7 +1350,7 @@ eolbyte = '\n'; filename_mask = ~0; - max_count = TYPE_MAXIMUM (off_t); + max_count = INTMAX_MAX; /* The value -1 means to use DEFAULT_CONTEXT. */ out_after = out_before = -1; @@ -1503,23 +1515,15 @@ break; case 'm': - { - uintmax_t value; - switch (xstrtoumax (optarg, 0, 10, &value, "")) - { - case LONGINT_OK: - max_count = value; - if (0 <= max_count && max_count == value) - break; - /* Fall through. */ - case LONGINT_OVERFLOW: - max_count = TYPE_MAXIMUM (off_t); - break; + switch (xstrtoimax (optarg, 0, 10, &max_count, "")) + { + case LONGINT_OK: + case LONGINT_OVERFLOW: + break; - default: - error (2, 0, _("invalid max count")); - } - } + default: + error (EXIT_FAILURE, 0, _("invalid max count")); + } break; case 'n': Index: gnu/dist/grep/src/kwset.c =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/src/kwset.c,v retrieving revision 1.1.1.2 diff -u -r1.1.1.2 kwset.c --- gnu/dist/grep/src/kwset.c 26 Jan 2003 23:15:30 -0000 1.1.1.2 +++ gnu/dist/grep/src/kwset.c 27 Dec 2012 14:00:10 -0000 @@ -61,7 +61,7 @@ /* Node of a trie representing a set of reversed keywords. */ struct trie { - unsigned int accepting; /* Word index of accepted word, or zero. */ + size_t accepting; /* Word index of accepted word, or zero. */ struct tree *links; /* Tree of edges leaving this node. */ struct trie *parent; /* Parent of this node. */ struct trie *next; /* List of all trie nodes in level order. */ @@ -75,7 +75,7 @@ struct kwset { struct obstack obstack; /* Obstack for node allocation. */ - int words; /* Number of words in the trie. */ + ptrdiff_t words; /* Number of words in the trie. */ struct trie *trie; /* The trie itself. */ int mind; /* Minimum depth of an accepting node. */ int maxd; /* Maximum depth of any node. */ Index: gnu/dist/grep/src/kwset.h =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/src/kwset.h,v retrieving revision 1.1.1.2 diff -u -r1.1.1.2 kwset.h --- gnu/dist/grep/src/kwset.h 26 Jan 2003 23:15:30 -0000 1.1.1.2 +++ gnu/dist/grep/src/kwset.h 27 Dec 2012 14:00:10 -0000 @@ -24,7 +24,7 @@ struct kwsmatch { - int index; /* Index number of matching keyword. */ + size_t index; /* Index number of matching keyword. */ size_t offset[1]; /* Offset of each submatch. */ size_t size[1]; /* Length of each submatch. */ }; Index: gnu/dist/grep/src/search.c =================================================================== RCS file: /cvsroot/src/gnu/dist/grep/src/search.c,v retrieving revision 1.3 diff -u -r1.3 search.c --- gnu/dist/grep/src/search.c 1 Aug 2008 15:24:35 -0000 1.3 +++ gnu/dist/grep/src/search.c 27 Dec 2012 14:00:12 -0000 @@ -339,7 +339,9 @@ { register char const *buflim, *beg, *end; char eol = eolbyte; - int backref, start, len; + int backref; + regoff_t start; + ptrdiff_t len; struct kwsmatch kwsm; size_t i; #ifdef MBS_SUPPORT Index: gnu/usr.bin/grep/lib/Makefile =================================================================== RCS file: /cvsroot/src/gnu/usr.bin/grep/lib/Makefile,v retrieving revision 1.5 diff -u -r1.5 Makefile --- gnu/usr.bin/grep/lib/Makefile 26 May 2011 12:56:28 -0000 1.5 +++ gnu/usr.bin/grep/lib/Makefile 27 Dec 2012 14:00:12 -0000 @@ -11,7 +11,7 @@ SRCS= closeout.c error.c exclude.c hard-locale.c isdir.c \ obstack.c quotearg.c regex.c savedir.c stpcpy.c \ - xmalloc.c xstrtol.c xstrtoumax.c + xmalloc.c xstrtol.c xstrtoimax.c COPTS.hard-locale.c = -Wno-stack-protector COPTS.regex.c = -Wno-stack-protector --- /dev/null 2012-12-27 15:00:37.000000000 +0100 +++ gnu/dist/grep/lib/xstrtoimax.c 2012-12-26 17:37:58.000000000 +0100 @@ -0,0 +1,6 @@ +#define __strtol strtoimax +#define __strtol_t intmax_t +#define __xstrtol xstrtoimax +#define STRTOL_T_MINIMUM INTMAX_MIN +#define STRTOL_T_MAXIMUM INTMAX_MAX +#include "xstrtol.c"