diff options
author | Michael Rash <mbr@cipherdyne.org> | 2006-08-22 03:45:22 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-08-22 17:33:58 -0400 |
commit | 3ffaa8c7c0f884171a273cd2145b8fbbf233ba22 (patch) | |
tree | 78529eb063987ea5f89980670c38c6cc7cba271b /lib/ts_bm.c | |
parent | 316c1592bea94ead75301cb764523661fbbcc1ca (diff) |
[TEXTSEARCH]: Fix Boyer Moore initialization bug
The pattern is set after trying to compute the prefix table, which tries
to use it. Initialize it before calling compute_prefix_tbl, make
compute_prefix_tbl consistently use only the data from struct ts_bm
and remove the now unnecessary arguments.
Signed-off-by: Michael Rash <mbr@cipherdyne.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/ts_bm.c')
-rw-r--r-- | lib/ts_bm.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/ts_bm.c b/lib/ts_bm.c index 0110e4414805..d90822c378a4 100644 --- a/lib/ts_bm.c +++ b/lib/ts_bm.c | |||
@@ -111,15 +111,14 @@ static int subpattern(u8 *pattern, int i, int j, int g) | |||
111 | return ret; | 111 | return ret; |
112 | } | 112 | } |
113 | 113 | ||
114 | static void compute_prefix_tbl(struct ts_bm *bm, const u8 *pattern, | 114 | static void compute_prefix_tbl(struct ts_bm *bm) |
115 | unsigned int len) | ||
116 | { | 115 | { |
117 | int i, j, g; | 116 | int i, j, g; |
118 | 117 | ||
119 | for (i = 0; i < ASIZE; i++) | 118 | for (i = 0; i < ASIZE; i++) |
120 | bm->bad_shift[i] = len; | 119 | bm->bad_shift[i] = bm->patlen; |
121 | for (i = 0; i < len - 1; i++) | 120 | for (i = 0; i < bm->patlen - 1; i++) |
122 | bm->bad_shift[pattern[i]] = len - 1 - i; | 121 | bm->bad_shift[bm->pattern[i]] = bm->patlen - 1 - i; |
123 | 122 | ||
124 | /* Compute the good shift array, used to match reocurrences | 123 | /* Compute the good shift array, used to match reocurrences |
125 | * of a subpattern */ | 124 | * of a subpattern */ |
@@ -150,8 +149,8 @@ static struct ts_config *bm_init(const void *pattern, unsigned int len, | |||
150 | bm = ts_config_priv(conf); | 149 | bm = ts_config_priv(conf); |
151 | bm->patlen = len; | 150 | bm->patlen = len; |
152 | bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len; | 151 | bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len; |
153 | compute_prefix_tbl(bm, pattern, len); | ||
154 | memcpy(bm->pattern, pattern, len); | 152 | memcpy(bm->pattern, pattern, len); |
153 | compute_prefix_tbl(bm); | ||
155 | 154 | ||
156 | return conf; | 155 | return conf; |
157 | } | 156 | } |