aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-07 16:02:52 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-07 16:05:35 +0100
commitc1cce962177242f408040e422741bd30a61ff0f1 (patch)
treece635b59592f1f0bb47e093be1e314dfb8f19b1b /src/libutil
parentfce8a9893305f18e7dc1e8970ffdc14aeb2d3ff1 (diff)
downloadrspamd-c1cce962177242f408040e422741bd30a61ff0f1.tar.gz
rspamd-c1cce962177242f408040e422741bd30a61ff0f1.zip
[Fix] Fix one character length substrings search
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/str_util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index f3e4a1f8c..595eca2f6 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -1288,6 +1288,18 @@ rspamd_substring_search (const gchar *in, gsize inlen,
const gchar *srch, gsize srchlen)
{
if (inlen > srchlen) {
+ if (G_UNLIKELY (srchlen == 1)) {
+ const gchar *p;
+
+ p = memchr (in, srch[0], inlen);
+
+ if (p) {
+ return p - in;
+ }
+
+ return (-1);
+ }
+
return rspamd_substring_search_common (in, inlen, srch, srchlen,
rspamd_substring_cmp_func);
}
@@ -1306,6 +1318,19 @@ rspamd_substring_search_caseless (const gchar *in, gsize inlen,
const gchar *srch, gsize srchlen)
{
if (inlen > srchlen) {
+ if (G_UNLIKELY (srchlen == 1)) {
+ goffset i;
+ gchar s = lc_map[(guchar)srch[0]];
+
+ for (i = 0; i < inlen; i++) {
+ if (lc_map[(guchar)in[i]] == s) {
+ return i;
+ }
+ }
+
+ return (-1);
+ }
+
return rspamd_substring_search_common (in, inlen, srch, srchlen,
rspamd_substring_casecmp_func);
}