Browse Source

[Minor] Fix substring search in case if inlen == srchlen

tags/1.5.5
Vsevolod Stakhov 7 years ago
parent
commit
d3385c8130
1 changed files with 28 additions and 23 deletions
  1. 28
    23
      src/libutil/str_util.c

+ 28
- 23
src/libutil/str_util.c View File

@@ -1229,36 +1229,41 @@ rspamd_substring_search_caseless (const gchar *in, gsize inlen,
gsize i, j;
gchar c1, c2;

if (inlen < srchlen) {
return -1;
}
/* Searching */
if (inlen > srchlen) {
/* Preprocessing */
for (d = i = 1; i < srchlen; ++i) {
/* computes d = 2^(m-1) with the left-shift operator */
d = (d << 1);
}

/* Preprocessing */
for (d = i = 1; i < srchlen; ++i) {
/* computes d = 2^(m-1) with the left-shift operator */
d = (d << 1);
}
for (hash_in = hash_srch = i = 0; i < srchlen; ++i) {
hash_srch = ((hash_srch << 1) + g_ascii_tolower (srch[i]));
hash_in = ((hash_in << 1) + g_ascii_tolower (in[i]));
}

for (hash_in = hash_srch = i = 0; i < srchlen; ++i) {
hash_srch = ((hash_srch << 1) + g_ascii_tolower (srch[i]));
hash_in = ((hash_in << 1) + g_ascii_tolower (in[i]));
}
j = 0;
while (j <= inlen - srchlen) {

/* Searching */
j = 0;
while (j <= inlen - srchlen) {
if (hash_srch == hash_in &&
rspamd_lc_cmp (srch, in + j, srchlen) == 0) {
return (goffset) j;
}

if (hash_srch == hash_in && rspamd_lc_cmp (srch, in + j, srchlen) == 0) {
return (goffset) j;
c1 = g_ascii_tolower (in[j]);
c2 = g_ascii_tolower (in[j + srchlen]);
hash_in = RKHASH (c1, c2, hash_in);
++j;
}

c1 = g_ascii_tolower (in[j]);
c2 = g_ascii_tolower (in[j + srchlen]);
hash_in = RKHASH (c1, c2, hash_in);
++j;
}
else if (inlen == srchlen) {
return rspamd_lc_cmp (srch, in, srchlen) == 0;
}
else {
return (-1);
}

return -1;
return (-1);
}

/* Computing of the maximal suffix for <= */

Loading…
Cancel
Save