Commit 3ffaa8c7 authored by Michael Rash's avatar Michael Rash Committed by David S. Miller

[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: default avatarMichael Rash <mbr@cipherdyne.org>
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 316c1592
...@@ -111,15 +111,14 @@ static int subpattern(u8 *pattern, int i, int j, int g) ...@@ -111,15 +111,14 @@ static int subpattern(u8 *pattern, int i, int j, int g)
return ret; return ret;
} }
static void compute_prefix_tbl(struct ts_bm *bm, const u8 *pattern, static void compute_prefix_tbl(struct ts_bm *bm)
unsigned int len)
{ {
int i, j, g; int i, j, g;
for (i = 0; i < ASIZE; i++) for (i = 0; i < ASIZE; i++)
bm->bad_shift[i] = len; bm->bad_shift[i] = bm->patlen;
for (i = 0; i < len - 1; i++) for (i = 0; i < bm->patlen - 1; i++)
bm->bad_shift[pattern[i]] = len - 1 - i; bm->bad_shift[bm->pattern[i]] = bm->patlen - 1 - i;
/* Compute the good shift array, used to match reocurrences /* Compute the good shift array, used to match reocurrences
* of a subpattern */ * of a subpattern */
...@@ -150,8 +149,8 @@ static struct ts_config *bm_init(const void *pattern, unsigned int len, ...@@ -150,8 +149,8 @@ static struct ts_config *bm_init(const void *pattern, unsigned int len,
bm = ts_config_priv(conf); bm = ts_config_priv(conf);
bm->patlen = len; bm->patlen = len;
bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len; bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len;
compute_prefix_tbl(bm, pattern, len);
memcpy(bm->pattern, pattern, len); memcpy(bm->pattern, pattern, len);
compute_prefix_tbl(bm);
return conf; return conf;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment