summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Rash <mbr@cipherdyne.org>2006-08-22 04:07:57 +0200
committerGreg Kroah-Hartman <gregkh@suse.de>2006-09-08 14:51:36 -0700
commit940d7bceb97c8989e700de946b0514acc9b739c5 (patch)
treed29a1d67d562e22313e81c9726618c2ab7e46b05
parentd2350c2ad1463a973b586cadb49c2fa0c83089b8 (diff)
downloadlwn-940d7bceb97c8989e700de946b0514acc9b739c5.tar.gz
lwn-940d7bceb97c8989e700de946b0514acc9b739c5.zip
TEXTSEARCH: Fix Boyer Moore initialization bug
[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> Acked-by: David Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--lib/ts_bm.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/ts_bm.c b/lib/ts_bm.c
index c4c1ac5fbd1a..791726579daa 100644
--- a/lib/ts_bm.c
+++ b/lib/ts_bm.c
@@ -112,15 +112,14 @@ static int subpattern(u8 *pattern, int i, int j, int g)
return ret;
}
-static void compute_prefix_tbl(struct ts_bm *bm, const u8 *pattern,
- unsigned int len)
+static void compute_prefix_tbl(struct ts_bm *bm)
{
int i, j, g;
for (i = 0; i < ASIZE; i++)
- bm->bad_shift[i] = len;
- for (i = 0; i < len - 1; i++)
- bm->bad_shift[pattern[i]] = len - 1 - i;
+ bm->bad_shift[i] = bm->patlen;
+ for (i = 0; i < bm->patlen - 1; i++)
+ bm->bad_shift[bm->pattern[i]] = bm->patlen - 1 - i;
/* Compute the good shift array, used to match reocurrences
* of a subpattern */
@@ -151,8 +150,8 @@ static struct ts_config *bm_init(const void *pattern, unsigned int len,
bm = ts_config_priv(conf);
bm->patlen = len;
bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len;
- compute_prefix_tbl(bm, pattern, len);
memcpy(bm->pattern, pattern, len);
+ compute_prefix_tbl(bm);
return conf;
}