summaryrefslogtreecommitdiff
path: root/src/kwset.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-02-29 00:41:00 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2012-03-01 07:46:03 -0800
commitcbbc1a45b9f843c811905c97c90a5d31f8e6c189 (patch)
tree8f68da634210a8b7342b27b0d2113ef7a9ec639f /src/kwset.c
parent235aad711285fc6978f6ff26397743930b23f79a (diff)
downloadgrep-cbbc1a45b9f843c811905c97c90a5d31f8e6c189.tar.gz
grep: fix some core dumps with long lines etc.
These problems mostly occur because the code attempts to stuff sizes into int or into unsigned int; this doesn't work on most 64-bit hosts and the errors can lead to core dumps. * NEWS: Document this. * src/dfa.c (token): Typedef to ptrdiff_t, since the enum's range could be as small as -128 .. 127 on practical hosts. (position.index): Now size_t, not unsigned int. (leaf_set.elems): Now size_t *, not unsigned int *. (dfa_state.hash, struct mb_char_classes.nchars, .nch_classes) (.nranges, .nequivs, .ncoll_elems, struct dfa.cindex, .calloc, .tindex) (.talloc, .depth, .nleaves, .nregexps, .nmultibyte_prop, .nmbcsets): (.mbcsets_alloc): Now size_t, not int. (dfa_state.first_end): Now token, not int. (state_num): New type. (struct mb_char_classes.cset): Now ptrdiff_t, not int. (struct dfa.utf8_anychar_classes): Now token[5], not int[5]. (struct dfa.sindex, .salloc, .tralloc): Now state_num, not int. (struct dfa.trans, .realtrans, .fails): Now state_num **, not int **. (struct dfa.newlines): Now state_num *, not int *. (prtok): Don't assume 'token' is no wider than int. (lexleft, parens, depth): Now size_t, not int. (charclass_index, nsubtoks) (parse_bracket_exp, addtok, copytoks, closure, insert, merge, delete) (state_index, epsclosure, state_separate_contexts) (dfaanalyze, dfastate, build_state, realloc_trans_if_necessary) (transit_state_singlebyte, match_anychar, match_mb_charset) (check_matching_with_multibyte_ops, transit_state_consume_1char) (transit_state, dfaexec, free_mbdata, dfaoptimize, dfafree) (freelist, enlist, addlists, inboth, dfamust): Don't assume indexes fit in 'int'. (lex): Avoid overflow in string-to-{hi,lo} conversions. (dfaanalyze): Redo indexing so that it works with size_t values, which cannot go negative. * src/dfa.h (dfaexec): Count argument is now size_t *, not int *. (dfastate): State numbers are now ptrdiff_t, not int. * src/dfasearch.c: Include "intprops.h", for TYPE_MAXIMUM. (kwset_exact_matches): Now size_t, not int. (EGexecute): Don't assume indexes fit in 'int'. Check for overflow before converting a ptrdiff_t to a regoff_t, as regoff_t is narrower than ptrdiff_t in 64-bit glibc (contra POSIX). Check for memory exhaustion in re_search rather than treating it merely as failure to match; use xalloc_die () to report any error. * src/kwset.c (struct trie.accepting): Now size_t, not unsigned int. (struct kwset.words): Now ptrdiff_t, not int. * src/kwset.h (struct kwsmatch.index): Now size_t, not int.
Diffstat (limited to 'src/kwset.c')
-rw-r--r--src/kwset.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/kwset.c b/src/kwset.c
index 7c37ab0e..54963719 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -62,7 +62,7 @@ struct tree
/* 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. */
@@ -76,7 +76,7 @@ struct trie
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. */