Commit 3ffaa8c7c0f884171a273cd2145b8fbbf233ba22

Authored by Michael Rash
Committed by David S. Miller
1 parent 316c1592be

[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>

Showing 1 changed file with 5 additions and 6 deletions Side-by-side Diff

... ... @@ -111,15 +111,14 @@
111 111 return ret;
112 112 }
113 113  
114   -static void compute_prefix_tbl(struct ts_bm *bm, const u8 *pattern,
115   - unsigned int len)
  114 +static void compute_prefix_tbl(struct ts_bm *bm)
116 115 {
117 116 int i, j, g;
118 117  
119 118 for (i = 0; i < ASIZE; i++)
120   - bm->bad_shift[i] = len;
121   - for (i = 0; i < len - 1; i++)
122   - bm->bad_shift[pattern[i]] = len - 1 - i;
  119 + bm->bad_shift[i] = bm->patlen;
  120 + for (i = 0; i < bm->patlen - 1; i++)
  121 + bm->bad_shift[bm->pattern[i]] = bm->patlen - 1 - i;
123 122  
124 123 /* Compute the good shift array, used to match reocurrences
125 124 * of a subpattern */
126 125  
... ... @@ -150,8 +149,8 @@
150 149 bm = ts_config_priv(conf);
151 150 bm->patlen = len;
152 151 bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len;
153   - compute_prefix_tbl(bm, pattern, len);
154 152 memcpy(bm->pattern, pattern, len);
  153 + compute_prefix_tbl(bm);
155 154  
156 155 return conf;
157 156 }